How to insert URL into flash messages?

给你一囗甜甜゛ 提交于 2019-12-12 06:07: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) ) does not works for me.

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


回答1:


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


来源:https://stackoverflow.com/questions/4550295/how-to-insert-url-into-flash-messages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!