I have a strange behavior of Rails 3.0.10. Got this application controller:
app/controllers/application_controller.rb
require 'api/api_controller'
# rest not important
app/controllers/api/api_controller.rb
class Api::ApiController < ActionController::Base
before_filter :require_user
def require_user
@user = User.find(xxx, yyy)
end
end
and then this controller:
app/controllers/api/ac_controller.rb
class Api::AcController < Api::ApiController
before_filter :find_pool, :only => [:add_pool, :remove_pool]
def add_pool
# some logic that needs @user to be set
end
def remove_pool
# some logic that needs @user to be set
end
def find_pool
# some logic here
end
end
My problem is when I run this in production mode the require_user filter is NOT called. When I try this in the development mode, it works.
Now, I understand in development mode classes are being reloaded, but the question is why the require_user filter does NOT get called?
Edit: Please note AC controller is before API controller lexicographically.
It looks like order of required files problem or the
ApiControllerbeing loaded twice. Once beforeAcControllerand one more time afterAcControllerbeing loaded. This could cause, thatfind_poolfilter will get evaluated beforerequire_user.ApiControlleris alse afterAcControllerin lex order.The problem might be caused by
require "api_controller"being present somewhere – it should be handled by Rails and does not need to be put down explicitly. So if there is such a line, removing it could help.