Search code examples
ruby-on-railsactionpack

What approach do you take for embedding links in flash messages?


The ability to have flash messages (notice, error, warning, etc) with embedded links is nice from a user interaction standpoint. However, embedding an anchor tag inside a flash message from the controller is dirty.

Let's assume that a flash message like this is good for usability*:

Example Flash Message Notice with an Embedded Link http://img.skitch.com/20090826-xbsa4tb3sjq4fig9nmatakthx3.png (borrowed from DailyMile.com)

What tactic would you take between the controller and view to employ something like this cleanly?


Solution

  • Just thought I would share this, since found answer I was looking for elsewhere:

    Works on rails 3.1

    flash[:notice] = "Proceed to #{view_context.link_to('login page', login_path)}".html_safe