pet*_*hka 9 inheritance ruby-on-rails ruby-on-rails-3
每次我收到警告:
app/controllers/agency/agencies_controller.rb:1: warning: toplevel constant ApplicationController referenced by Agency::ApplicationController
Run Code Online (Sandbox Code Playgroud)
我的agencies_controller.rb:
class Agency::AgenciesController < Agency::ApplicationController
def index
...
end
...
end
Run Code Online (Sandbox Code Playgroud)
和Agency :: ApplicationController:
class Agency::ApplicationController < ApplicationController
layout 'agency'
helper_method :current_agency
private
def current_agency
@current_agency ||= current_user.agency
end
end
Run Code Online (Sandbox Code Playgroud)
铁轨对我有什么要求?有什么麻烦?
与另一个控制器相同的情况
class Agency::ClientsController < Agency::ApplicationController
...
end
Run Code Online (Sandbox Code Playgroud)
没有警告,没有错误......
我跑了类似的问题Spork
,并Watchr
在我的Admin
命名空间的控制器.所以我通过在each_run
块中添加以下代码来解决这个问题spec_helper.rb
:
Dir[File.expand_path("app/controllers/admin/*.rb")].each do |file|
require file
end
Run Code Online (Sandbox Code Playgroud)
所有积分都来自这个帖子
ApplicationController
是您创建所有其他控制器类继承的新项目时Rails为您生成的超类控制器的名称.在某处可能存在冲突,因为您使用了相同的名称,即使您将其放在命名空间中也是如此.
尝试给你Agency::ApplicationController
一个不同的名字.