at.
at.

Reputation: 52500

flash message in Rails stays until next webpage

When I use rails' redirect_to method in a controller and pass it a notice message, everything works great. The notice is shown at the top for the page redirected to and then disappears when the next page is visited.

However, if I instead set a flash message and then simply render a page, then the flash message is shown, but it's also shown on the next page visited:

flash[:alert] = 'Please fix mistakes outlined in red'
render action: 'show'

How do I not make the alert message show on the next page that's visited. I only want that alert message shown on this page being rendered.

Using Rails 3.2.8

Upvotes: 3

Views: 1379

Answers (1)

jdoe
jdoe

Reputation: 15771

Use now method:

flash.now[:alert] = 'Please fix mistakes outlined in red'

Upvotes: 8

Related Questions