开发者

How to insert URL into flash messages?

开发者 https://www.devze.com 2023-02-01 06:51 出处:网络
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) )开发者_StackOverflow中文版 does not works for me.

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) )开发者_StackOverflow中文版 does not works for me.

I want to add a link to the 'root_path'.


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>."

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] %>
0

精彩评论

暂无评论...
验证码 换一张
取 消