Rails activeadmin dropdown menu in new and editable forms

I have a has_many belongs_to association. I registered a resource. I have shipment owned by customers.

But when I switch to the new submission form, select for customers from the drop-down menu, I get # <0X0000>

Why? How can i fix this?

I think this is because the Customers table does not have the "name" attribute, instead I have a company_name. How can I use company_name in the dropdown menu?

+4
source share
4 answers

You do not have to override the to_s method , the active administrator can use the display_name method specifically for this case.

so you can add next to your model

def display_name company_name end 
+16
source

One option is to override to_s

 def to_s company_name end 

Another variant:

 f.input :customer, :as => :select, :label_method => : company_name , :value_method => :id 
+7
source
 f.input :customer, :label_method => :company_name 
+4
source

define the "to_s" method in your client model. Something like that:

 def to_s company_name end 
0
source

Source: https://habr.com/ru/post/1387226/


All Articles