Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails activeadmin drop down menu on new and edit forms [duplicate]

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?

like image 753
leonel Avatar asked Nov 28 '22 14:11

leonel


2 Answers

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
like image 59
Fivell Avatar answered Dec 01 '22 01:12

Fivell


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
like image 23
Tony Avatar answered Dec 01 '22 00:12

Tony