[英]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. 我有一个客户列表,但在右栏的过滤器部分,我在选择菜单中得到了一个类似
#<Customer0X0B500>
的列表。 How can I display the company_name attribute of Customer instead? 如何显示Customer的company_name属性?
想出来,谢谢!
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 我不确定我理解你,但可能你应该在Customer类中定义to_s方法,例如
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... 定义display_name而不是to_s效果更好......
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. 这将使您的company_name在视图页面上显示为标题,而不是公司#x。
To make ActiveAdmin display select menu properly try in Model.rb:- 要使ActiveAdmin显示选择菜单,请在Model.rb中尝试: -
alias_attribute :name, :category_name alias_attribute:name,:category_name
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.