Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding before and after_filter

I have the following code right after my controller class declaration

  before_filter :load_form, :except => [:create, :update, :delete]
  after_filter :load_form, :only => [:create, :update, :delete]

  def load_form
    @severities = Severity.all
    @severity = Severity.new
  end

I get the list of severities when the page loads just fine, meaning that the before_filter is working. However after calling a method such as create the list of severities always comes back as nil. I think I am probably just missing some fundamental thing about filters. Can anyone help me understand why the after_filter does not work?

like image 790
Jason Yost Avatar asked Dec 10 '22 09:12

Jason Yost


1 Answers

If you were expecting to see variables in your view that were assigned in your 'after' filter, that won't work because the filter is not executed until after your view has been completely processed.

like image 81
Steve Jorgensen Avatar answered Jan 05 '23 13:01

Steve Jorgensen