A very extreme case, I know, but I thought you may want to know about.
When defined a relationship where the name of the field doesn't give any information about the other model a lot has to be specified by hand in the belongs_to line. When that is the case, auto-admin seems to go crazy and generate two problems:
- The combo-boxes (selects) for those fields appear twice.
- Saving fails.
For your convenience I'd give you the steps to set it up (based on my own case):
1) Generate the models:
rails script/generate model Unit
rails script/generate model UnitConversion
2) Write the schemas (in migration):
create_table :units do |t|
t.column :name, :string, :null => false
t.column :symbol, :string, :null => true
end
create_table :unit_conversions do |t|
t.column :from, :integer, :null => false
t.column :to, :integer, :null => false
t.column :rate, :float, :null => false
end
3) Enhance the model with relationships:
class UnitConversion < ActiveRecord::Base
belongs_to :from, :class_name => "Unit", :foreign_key => "from"
belongs_to :to, :class_name => "Unit", :foreign_key => "to"
end
And voila! Add a couple of units and then try to add a conversion between them.
If you need any other feedback, let me know and I'll try to gather it for you.
BTW, excellent plug in, I am very thankful that you wrote it. Thank you!