Rails 6 expected file to define constant

Viewed 2123

I just created my first Rails 6 project ruby 2.7.0 rails 6.0.3. I have the following file:

#app\models\foo.rb

class Foo
  def initialize
  end

  def bar
   puts("Whoohoo!")
  end
end

From rails console I am trying to run:

foo = Foo.new

And I keep getting the error:

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

Coming from Rails 5 I'm lost as to what I'm doing wrong.

1 Answers

Can be that puts("Whoohoo!) missing a quote, but the syntax parser would get, so I'm assuming that is not the case.

You can call ActiveSupport::Dependencies.autoload_paths in rails console to consult if your model it is actually being loaded.

Related