Adding a Link Within a Flash Notice/Message – Ruby on Rails

I came across an instance where I needed to add a link to flash notice tonight. Manually creating a hyperlink seems to work fine, however I was chasing a rubyish way of doing things:

flash[:notice] = "Order created - Click <a href='orders/" + + "'>here</a> to pay for it!"


Luckily a quick Google revealed the answer:

flash[:notice] = "Order created - Click <a href='#{url_for(@order)}'>here</a> to pay for it!".html_safe


If you’re using rails 3 make sure you throw in the .html_safe or your link will be appear as plain text. Just a quick screenshot of the end result below:

Anyway, that’s all. Good Luck!

Leave a Reply