Ruby-on-rails – How to display a Rails flash notice upon redirect


I have the following code in a Rails controller:[:notice] = 'Successfully checked in'
redirect_to check_in_path

Then in the /check_in view:

<p id="notice"><%= notice %></p>

However, the notice does not show up. Works perfect if I don't redirect in the controller:[:notice] = 'Successfully checked in'
render action: 'check_in'

I need a redirect though… not just a rendering of that action. Can I have a flash notice after redirecting?

Best Solution

Remove the .now. So just write:

flash[:notice] = 'Successfully checked in'
redirect_to check_in_path

The .now is specifically supposed to be used when you are just rendering and not redirecting. When redirecting, the .now is not to be used.

Related Question