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

时光怂恿深爱的人放手 提交于 2019-12-19 09:21:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!