Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flash message in redirect not working

Do some tail'ing on your logs and see if you're being redirected to multiple actions before you render. If you are, it's likely that flash isn't being kept long enough to make it to the view where it is finally rendered.

A well-placed flash.keep(:notice) should do the trick.

Much later edit: Also, in retrospect, if you're redirecting that many times, I highly suggest you do some refactoring and eliminate any unnecessary jumps by consolidating your redirect logic at a higher level, so that your redirects are predetermined and only happen once, twice max.


simple, but effective:

modify ApplicationController < ActionController::Base as follows:

alias :std_redirect_to :redirect_to
def redirect_to(*args)
   flash.keep
   std_redirect_to *args
end

Best approach is to write these line in views/layouts/application.html.erb file

<%= notice %>
<%= alert %>

and write

layout 'application' in controllers


IN your controller use:

redirect_to signin_path, :notice => "There is already an acount for this email. Please Login to create your board."

In your application layout use:

<%= notice %>