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].


Posted

in

, ,

by

Comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a website or blog at WordPress.com

%d bloggers like this: