gpt4 book ai didi

ruby-on-rails - 为什么 Rubymine 无法识别我的命名空间继承 Controller ?

转载 作者:数据小太阳 更新时间:2023-10-29 08:42:43 25 4
gpt4 key购买 nike

我有一个名为 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 向我显示以下错误:

Expected: ; or end of line

此代码适用于 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com