Rails is ignoring my filter definition in ApplicationController
In rails 2.3.8 I'm trying to get a basic before_filter working. It works if I do these things in individual controllers, but now I want to do this in my ApplicationController.
class ApplicationController < ActionController::Base
before_filter :hello
private
def hello
puts "HELLO!"
end
end
I'm expecting this to cause it run h开发者_开发技巧ello before running any of my controller actions, without the need to reference filters at all in my other controller classes. But it seems to just ignore it (never calling 'hello') Why might that be?
All other controllers should inherit from ApplicationController so for example:
class MyOtherController < ApplicationController
Only the ApplicationController should inherit from ActionController::Base
Rails was ignoring my before filter because I'd declared my other controller to be also inheriting from ActionController::Base.
At least I thought this was clear, but reading this Action Controller Overview guide, it gives examples (some of the time) of other controllers inheriting from ActionController::Base . So that's confusing. In any case it fixes my problem if I always inherit from ActionController
I know this won't help you, but your code is correct and works when I tested it, though on Rails 3.
精彩评论