如何将URL插入Flash消息? [英] How to insert URL into flash messages?
本文介绍了如何将URL插入Flash消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我阅读了这个(1)和这个(2)但我希望有一个简单的方法要做到这一点......那就有效! ((1)和(2))都不适用于我。
I read this (1) and this (2) but I'd like to have a simple method to do that... and that works! Both ( (1) and (2) ) does not works for me.
我想添加一个指向'root_path'的链接。
I want to add a link to the 'root_path'.
推荐答案
你需要做两件事:首先,构建一个带有链接的flash消息,正如你所期望的那样:
You need to do two things: First, construct a flash message with a link in it, as you'd expect:
flash[:notice] = "Settings updated! <a href=\"#{root_path}\">Go home</a>."
然后,在您的视图中,您需要将其作为原始内容回显。这会跳过Rails 3自动转义受污染的字符串,因此请确保您永远不会通过此闪存传递用户输入:
Then, in your view, you'll need to echo it as raw content. This skips Rails 3's automatic escaping of tainted strings, so be sure you never pass user input through this flash:
<%=raw flash[:notice] %>
这篇关于如何将URL插入Flash消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文