Tag Archives: notices

Flash Notice Appearing Twice – Ruby on Rails

Ran into another flash notice issue, my messages were not disappearing after the first view. My code was as follows:

#Create flash warning
flash[:warning] = ("This product has been replaced: " +new_product.title + "").html_safe

It turns out that all you have to do to fix this issue is the following:

flash.now[:warning] = ("This product has been replaced: " +new_product.title + "").html_safe

This blog gives a brief overview of when to use flash.now[notice] and when to use flash[:notice]. A basic rule of thumb is that if you’re using a redirect, use flash[:notice], if you’re simply rendering a view, use flash.now[:notice].

Advertisements

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 here to pay for it!"

 

Luckily a quick Google revealed the answer:

flash[:notice] = "Order created - Click here 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!