简体   繁体   中英

Rails 3 and ActiveAdmin. Filter is displaying Objects not the company name

I have a list of customers but on the filter section on the right column, I get a list like this #<Customer0X0B500> in the select menu. How can I display the company_name attribute of Customer instead?

想出来,谢谢!

filter :customer, :collection => proc {(Customer.all).map{|c| [c.company_name, c.id]}}

i'm not sure I understand you but probably you should define to_s method inside your Customer class eg

class Customer

  def to_s
    self.company_name
  end

end

it would be easier if you shared some code

class Customer

  def display_name
    self.company_name
  end

end

Defining display_name instead of to_s works better...

  • to_s may be called automatically by other objects.
  • display_name only affects ActiveAdmin

You can also define:

show :title => :display_name

This will make your company_name appear as the title on the view pages instead of Company #x.

To make ActiveAdmin display select menu properly try in Model.rb:-

alias_attribute :name, :category_name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM