rails: Rails 6.0.3.2, after enable zeitwerk, it not work with enum helper method

(Copied from https://github.com/fxn/zeitwerk/issues/130, opened by @zw963.)

Following is a example:

# app/models/house.rb
class House < ActiveRecord::Base
  enum status: [:listed, :unlisted, :cancelled, :removed, :ghost]
end

When we use it in another model, we expected House.statuses is return a array.

House.statuses 
{
       "listed" => 0,
     "unlisted" => 1,
    "cancelled" => 2,
      "removed" => 3,
        "ghost" => 4
}

But, we got following error:

NoMethodError: undefined method `statuses’ for #Class:0x0000561fd65d53d0

In fact, ActiveRecord enum plugin never working.

# we expect it return ":listed" instead of 0.
House.last.status # => 0

All enum behavior works as expected if remove following config from config/application.rb

config.autoloader = :zeitwerk
config.add_autoload_paths_to_load_path = false

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 36 (18 by maintainers)

Most upvoted comments

Oh, please always stop Spring.

That was a good chase, thanks a lot for your persistence sending all the traces!