I've just upgraded to Rails 7, and suddenly I'm having a very odd issue with one of my models.
This is the model (please ignore the terrible naming of the keys and the fact that this would probably be better-suited as a boolean – it's legacy code ):
class Product < ApplicationRecord
FIREARM_NAMES = %w{ Frame Pistol Receiver Revolver Rifle Shotgun }
PAGINATE_BY = 24
enum map_price_source: [:map_source_is_distributor, :map_source_is_brand]
...
end
And when I try to load the class in a Rails console (either by just calling Product
or by instantiating it via Product.last
), the following error message is thrown:
ArgumentError: You tried to define an enum named "map_price_source" on the model "Product", but this will generate a instance method "map_source_is_distributor?", which is already defined by another enum.
map_price_source
is the only enum in the Product
class so map_source_is_distributor
can't be used by two different enums in Product
. And, in fact, that enum value is unique across the entire application.
Furthermore, I'm getting some warnings in console as well:
.../app/models/product.rb:3: warning: already initialized constant Product::FIREARM_NAMES
.../app/models/product.rb:3: warning: previous definition of FIREARM_NAMES was here
.../app/models/product.rb:4: warning: already initialized constant Product::PAGINATE_BY
.../app/models/product.rb:4: warning: previous definition of PAGINATE_BY was here
The error and the warnings seem to indicate that the Product
class is somehow being loaded more than once. And even more odd, as far as I can tell this is the only class that this is happening for.
If anyone has any clue what could be causing this, I'd be extremely grateful.