Created by: gracewashere
Fixes #145 (closed) and #219 (closed)
Problem:
When the same has_and_belongs_to_many
relationship is defined twice,
Rails generates an unnamed subclass of ActiveRecord::Base
.
This is probably a bug in Rails.
The unnamed subclass shows up like this:
> ActiveRecord::Base.descendants.last
#<Class:0x007fddea1bdf08> (call '#<Class:0x007fddea1bdf08>.connection' to establish a connection)
When the install generator tries to populate the DashboardManifest
with all of the ActiveRecord
models,
it trips up on unnamed models,
and generates a manifest with invalid syntax.
This results in a NameError
for the user when they run the
administrate:install
generator:
/gems/administrate-0.1.0/lib/generators/administrate/dashboard/dashboard_generator.rb:87:
in `const_get': wrong constant name #<class:0x007fcf52bfe248> (NameError)
This error most often pops up in applications
that are using the spring
gem.
Solution:
- Add a test case that reproduces the error
by defining duplicate
has_many
associations. - In the install generator, ignore any models that are not constants.
We determine constants by checking that the model's
#name
matches its#to_s
. - Print a warning for the ignored models.