ruby - Rails flash.now within after_action -


The code speaks for itself on it.

This works ...

  Classes some controllers & lt; ApplicationController DEF Index Flash. Now [: Warning] = 'Some have got bored!' End and << / code> 

and this is not ( flash is empty) ...

  class SomeController < ApplicationController after_action: test_flashdef index and def test_flash flash. Now [: Warning] = 'Some have got bored!'     

--Eytmprop = "text">

At the end of your index action rails, you new refer to the page, as if you have not specified anything different, after the index page is rendered, after_action is executed, it adds a callback after the index action is completed Will be said. Therefore, test_flash has no effect because it is too late and the index page has already been provided.

Edit:

If you want to call test_flash before rendering, you can override the Render method and do something like this:

  def render * args test_flash super end  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -