Search code examples
ruby-on-railshttp-redirectflash-message

How to display a flash message after multiple redirects?


So I'm trying to display a flash after multiple redirects, but I can't get it to "keep"! I tested out the code in my view file, and that's solid. What am I missing?

if response["status"] == "NotProcessed"
  redirect_to root_path, alert: "Does this work?"

That takes me back tot he root path, but no flash is displayed, so I added flash.keep, and still nothing. I even added:

      def redirect_to(*args)
        flash.keep
        super
      end

to my application controller... but nothing!

Thanks!


Solution

  • Fixed!

    I had set protect_from_forgery with: :null_session in my ApplicationController, thus it removed the flash with each session. I removed that and it works fine.

    I must have inserted that early on in the application when dealing with a weather API.