Rails3: warning: toplevel constant ApplicationController referenced by
Everytime i get a warning:
app/controllers/agency/agencies_controller.rb:1: warning: toplevel constant ApplicationController referenced by Agency::ApplicationController
My agencies_controller.rb:
class Agency::AgenciesController < Agency::ApplicationController
def index
...
end
...
end
And Agency::ApplicationController:
class Agenc开发者_高级运维y::ApplicationController < ApplicationController
layout 'agency'
helper_method :current_agency
private
def current_agency
@current_agency ||= current_user.agency
end
end
What the rails wants from me? What is the trouble?
Same situation with another controller
class Agency::ClientsController < Agency::ApplicationController
...
end
And no warnings, no errors...
I realize this question is almost two years old but I recently stumbled upon this through another stackoverflow post and wanted to share some insight.
Basically, if your namespace Agency
happens to be a class
instead of a module
, you'll get that warning. In the stackoverflow post I pasted above, they had a model (class
) of Admin
and their namespace was also Admin
.
This provides a better explanation of what is happening.
So check to see if your code isn't defining an Agency
class somewhere. Good luck.
I had similar issues running Spork
and Watchr
in my Admin
namespaced controllers. So i've fixed this by adding following code into each_run
block in spec_helper.rb
:
Dir[File.expand_path("app/controllers/admin/*.rb")].each do |file|
require file
end
All credits goes to guy from this thread
ApplicationController
is the name of the superclass controller that Rails generates for you when you create a new project that all your other controller classes inherit from. There's probably a conflict somewhere because you've used the same name, even though you put it within a namespace.
Try giving your Agency::ApplicationController
a different name.
I had similar issues, after setting up Spork
and Watchr
. In the process, I turned off class cacheing (config_cache_classes => false
in config/environments/test.rb
) so that changes would be reloaded as necessary in the spork environment. Turning class cacheing back on
made the warnings go away.
In my case it was the problem with Devise. I had a devise model Admin and a namespaced routes Admin. Changing the namespaced route to Admins solved the problem.
Solution for me was add this line:
# spec/rails_helper.rb
Dir[File.expand_path("app/controllers/admin/*.rb")].each { |file| require file }
精彩评论