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

HABTM relation causes NameError - uninitialized constant Model1::HabtmModel2 #123

Closed
Meekohi opened this issue Nov 18, 2014 · 6 comments
Closed
Assignees
Labels

Comments

@Meekohi
Copy link

Meekohi commented Nov 18, 2014

class Artist < ActiveRecord::Base
    has_and_belongs_to_many :events
end
class Event < ActiveRecord::Base
    has_and_belongs_to_many :artists
end

when I visit /admin I get the error
NameError - uninitialized constant Artist::HabtmEvents:
stack trace: https://gist.github.com/Meekohi/199d798b109a8a5212fe

Although using them on the rails console seems to work fine.

@ernsheong
Copy link

You can whitelist the models that appear as described here:
https://github.com/upmin/upmin-admin-ruby/wiki/Configurations

@mbrookes
Copy link
Contributor

Thanks Jonathan. Michael this looks like this is related #112 (or at least @ernsheong's issue). Let me know if setting config.models works for you, and I"ll close this one and track the issue there.

@Meekohi
Copy link
Author

Meekohi commented Nov 19, 2014

Yup I can confirm this works config/initializers/upmin_admin.rb:

Upmin.configure do |config|
  config.models = [:user, :event, :artist]
end

@Meekohi Meekohi closed this as completed Nov 19, 2014
@mbrookes
Copy link
Contributor

Looking at this again, I think @ernsheong's and your issue is different to the one @mfa123 originally reported at #112, so I think it deserves its own issue.

@mbrookes mbrookes reopened this Nov 19, 2014
@mbrookes mbrookes changed the title has_and_belongs_to_many relation causes NameError - uninitialized constant Model::HabtmEvents error HABTM relation causes NameError - uninitialized constant Model1::HabtmModel2 Nov 19, 2014
@mbrookes mbrookes added the bug label Nov 20, 2014
@mbrookes mbrookes self-assigned this Nov 20, 2014
@cassidyclawson
Copy link

I am also having this problem. Coincidently the HABTM models in question are precisely the models that require much hands on administration. I hope this issue can be resolved because I am otherwise very excited about this project!

@mbrookes
Copy link
Contributor

Hey @cassidyclawson, so the good news is there's already a PR in for this with #126 :) but it might be a little while before this make is into the codebase and a released version of the gem. However there's an easy workaround by configuring which models to display: https://github.com/upmin/upmin-admin-ruby/wiki/Configurations as @ernsheong mentioned. Let me know how you get on!

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

No branches or pull requests

4 participants