我正在使用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.'
答案 0 :(得分:12)
您可以使用方法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
。
答案 1 :(得分:4)
我无法实施这些解决方案。我需要的只是Flash中的一个简单的HTML链接。以下是我在Rails 4.1中实现它的方法。我只需要在app / views / shared / _flash.html.erb:
中清理我的flash消息<% flash.each do |name, msg| %>
<div class="alert alert-<%= name %>">
<a class="close" data-dismiss="alert">×</a>
<% if msg.is_a?(String) %>
<div id="flash_<%= name %>"> <%= sanitize(msg) %> </div>
<% end %>
</div>
<% end %>
在我的控制器中,我只是直接输入HTML而没有.html_safe。干得好!
flash[:notice] = %Q[Please <a href="#">click here</a>]