【问题标题】:Rails 6 expected file to define constantRails 6 预期文件定义常量
【发布时间】:2020-09-14 19:22:45
【问题描述】:

我刚刚创建了我的第一个 Rails 6 项目ruby 2.7.0 rails 6.0.3。 我有以下文件:

#app\models\foo.rb

class Foo
  def initialize
  end

  def bar
   puts("Whoohoo!")
  end
end

来自rails console 我正在尝试运行:

foo = Foo.new

我不断收到错误:

Zeitwerk::NameError (expected file <mypath>/app/models/foo.rb to define constant Foo, but didn't)

来自 Rails 5,我不知道自己做错了什么。

【问题讨论】:

标签: ruby-on-rails ruby ruby-on-rails-6


【解决方案1】:

可能是puts("Whoohoo!) 缺少引号,但语法解析器会得到,所以我假设情况并非如此。

您可以在rails console 中致电ActiveSupport::Dependencies.autoload_paths 以咨询您的模型是否实际正在加载。

【讨论】:

    猜你喜欢
    • 2020-02-06
    • 1970-01-01
    • 1970-01-01
    • 2019-12-25
    • 2011-01-25
    • 1970-01-01
    • 1970-01-01
    • 2012-01-02
    • 2020-04-29
    相关资源
    最近更新 更多