问题
I have a has_many belongs_to association. I registered the resource. I have shipments that belong to customers.
But when I go to the new shipment form, in the drop down select menu for customers I get #<0X0000>
Why? How can I fix it?
I think it's because the Customers table doesn't have a "name" attribute, instead I have company_name. How can I use company_name in the drop down menu?
回答1:
You shouldn't override to_s method, active admin can use display_name method specially for this case
so you can add next to your model
def display_name
company_name
end
回答2:
One option is to override to_s
def to_s
company_name
end
Other option is the following:
f.input :customer, :as => :select, :label_method => : company_name , :value_method => :id
回答3:
f.input :customer, :label_method => :company_name
回答4:
define a "to_s" method on your customer model. Something like this:
def to_s
company_name
end
来源:https://stackoverflow.com/questions/8578819/rails-activeadmin-drop-down-menu-on-new-and-edit-forms