What order do before filters occur in? Specifically, what order do the before_action filters occur in, in regards to inheiritance? For example, will this work:
class A < ActionController::Base
before_action :set_user
def set_user
@user = something
end
end
class B < A
before_action :set_post
def show
render @post
end
def set_post
@post = @user.posts.first
end
end
Will B#show work? What are the rules for filter order for future reference? I can't find any of this in the Rails documentation.
I suggest taking a look at the source code and API Docs on filters.
The default ordering should be
:set_post:set_userI think if you wanted to push
:set_userto the top of the stack you could change the line inAtoAlso worth pointing out, this isn't the only question on the topic; there are others here on SO.
As for your specific situation, it looks like you'll need to change
Aas I mentioned above in order to have@userbe assigned by the timeset_postinBruns.As of 4.2.6 (probably changed in an earlier version), the ordering is now parent before child:
:set_user:set_post