是否可以在确认后添加闪存消息的链接?
我正在使用Devise。
当用户成功确认时,将显示flash消息。
我想添加一个链接。
所以我想要这条消息
Your account was successfully confirmed. You are now signed in. Go to your profile page, and edit it!
然后, profile
的一部分应该是example.com/users/username/edit
的链接
我怎样才能成功呢?
devise.en.yml
confirmations: confirmed: 'Your account was successfully confirmed. You are now signed in.'
我无法实施这些解决方案。 我只需要一个简单的HTML链接。 这是我在Rails 4.1中实现它的方式。 我只需要在app / views / shared / _flash.html.erb中清理我的flash消息:
<% flash.each do |name, msg| %> × <% if msg.is_a?(String) %> <%= sanitize(msg) %> <% end %> <% end %>
在我的控制器中,我只是直接输入HTML而没有.html_safe。 干得好吃!
flash[:notice] = %Q[Please click here]
您可以使用方法view_context
访问模型和控制器中的任何视图方法。
例如:
def index flash[:notice] = "Go to your #{view_context.link_to("profile page", link_path)}, and edit it!" redirect_to link_path end
相应地更新link_path
。