← Back to Upcase

Flash.now.notice vs. flash.notice


(Olga Grabek) #1

In the SessionController Monban gem generate a method: set_flash_message. Inside that method the flash.now.notice is set. I wonder what is the difference between setting flash.now.notice and flash.notice ?

How should I render flash.now.notice? In my layouts/application.html.erb I tried:

<%= notice if notice %>

but it didn’t work. After incorrect logging I was redirected to root path but the notice doesn’t show.


(Ben Orenstein) #2

This provides some good info on the difference between the normal flash and flash.now: http://guides.rubyonrails.org/action_controller_overview.html#the-flash

As far as displaying the flash, you’d need something like:

<%= flash.notice if flash.notice %>

I don’t think notice refers to anything on its own.

One other thing that might be part of your issue: data in flash.now gets cleared out when you have a new request (which happens when you redirect). If you want to store a message to be displayed after a redirect you’ll need to use flash.notice, not flash.now.

Hope that helps!