I'm using Devise.
When the user succeeded at confirmation, the flash message appears.
I'd like to add a link to it.
So I want this message instead
Your account was successfully confirmed. You are now signed in. Go to your profile page, and edit it!
Then the part of profile
should be the link to example.com/users/username/edit
How can I make it possible?
devise.en.yml
confirmations:
confirmed: 'Your account was successfully confirmed. You are now signed in.'
You can use the method view_context
to access any view method inside your models and controllers.
For example:
def index
flash[:notice] = "Go to your #{view_context.link_to("profile page", link_path)}, and edit it!"
redirect_to link_path
end
Update link_path
accordingly.
I had trouble implementing these solutions. All I needed was a simple HTML link in the flash. Here's how I implemented it in Rails 4.1. I just had to sanitize my flash messages in app/views/shared/_flash.html.erb:
<% 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 %>
And in my controller, I just entered HTML directly and without .html_safe. Works a treat!
flash[:notice] = %Q[Please <a href="#">click here</a>]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With