I would like to render a link inside a flash message in Rails 3. I’m setting the flash message in the controller like this:
flash.notice = render_to_string 'shared/message_with_a_link', :layout => nil
This works just fine.
But then let’s say I already have a flash message to render, and I just want to append the message with the link. I tried switching = to +=, like so
flash.notice += render_to_string 'shared/message_with_a_link', :layout => nil
And now the flash div contains both messages, but the link has been escaped, so it shows up as <a href="google.com">google</a> instead of google.
Does anyone know why the flash would be escaped in the second case but not the first?
Use
.html_safeon your string.More info here.