Search code examples
ruby-on-railsruby-on-rails-3cookiesruby-on-rails-3.2flash-message

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


Solution

  • Use now method:

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