Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uninitialized Constant when Loading Classy Enum in 4.0.0 #51

Closed
SingleShot opened this issue Jan 25, 2015 · 3 comments
Closed

Uninitialized Constant when Loading Classy Enum in 4.0.0 #51

SingleShot opened this issue Jan 25, 2015 · 3 comments

Comments

@SingleShot
Copy link

I added a 4.0.0 classy_enum to an active record like so (ruby: 2.1.4, rails: 4.2.0):

class Membership < ActiveRecord::Base
  include ClassyEnum::ActiveRecord
  classy_enum_attr :status, class_name: 'MembershipStatus'
  ...
end

This active record joins two other tables (User and Group), and defaults the enum value to "pending".

Attempting to load the enum from the database yields:

NameError: uninitialized constant MembershipStatus

For example, with:

Group.find(2).memberships

Downgrading to 3.5.0 without any code changes fixes the problem:

Group.find(2).memberships[0].status.text
 => "Pending"
@beerlington
Copy link
Owner

Thanks for the info. I think this has to do with an auto load issue also reported here. I should have some time later today to dig into this more. For now you should be able to get around it by adding app/enums to your autoload paths.

@beerlington
Copy link
Owner

@SingleShot I'm trying to recreate this issue with my own Rails demo app and cannot seem to do so. Here's an example app which uses Rails 4.2 and ClassyEnum 4.0.0. I've tested with Ruby 2.1.4 and 2.1.5 and the enum is autoloading just fine.

Would it be possible for you to create an example app that demonstrates the issue? If not, maybe post your MembershipStatus enum class? Can you also confirm that the enum is in app/enums/membership_status.rb?

I am having an issue with Ruby 2.2.0, but it seems to be unrelated.

@beerlington
Copy link
Owner

Closing in favor of #50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants