我有一个名为 backend
的命名空间和以下 Controller application_controller.rb
:
class Backend::ApplicationController < ApplicationController
end
现在我从我的用户 Controller 继承这个 Controller :
class Backend::UserController < Backend::ApplicationController
def index
@users = User.all
end
...
end
对于应用程序 Controller 的继承,Rubymine 显示了以下错误:
这段代码对于 ruby 解释器来说很好。我怎样才能把这个教给 Rubymine?
我使用的是 RubyMine 2018.2.3 并使用 Ruby 2.5.1p57。
提前谢谢您!
最佳答案
我猜您应该尝试正确的“常规”方式来实际打开模块。
这两种方法实际上并不等同:
class Backend::ApplicationController < ApplicationController
end
module Backend
class ApplicationController < ::ApplicationController
end
end
由于后者实际上正确设置了模块嵌套以按预期工作:
module Backend
# this class will inherit from Backend::ApplicationController
# and not ::ApplicationController
class UserController < ApplicationController
end
end
一般来说,应避免“命名空间”类的“快捷方式”定义(class Foo::Bar
),因为它会导致持续查找出现问题。
关于ruby-on-rails - 为什么 Rubymine 无法识别我的命名空间继承 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52671899/