Flash.now.notice vs. flash.notice

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.

This provides some good info on the difference between the normal flash and flash.now: Action Controller Overview — Ruby on Rails Guides

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!

1 Like