Active_admin和:过滤器

时间:2012-02-18 21:40:38

标签: ruby-on-rails-3.1 filter associations activeadmin

问题在于:filter:contact,:as => :如果我键入联系人的ID,字符串可以正常工作。但是当你有2000多个联系人时,那是不切实际的。如何成功过滤:contact,as => :string但要搜索:name而不是:id。

我尝试过以下操作但没有成功:

filter :contact, :as => :string, :collection => proc {Contact.where(:name => 'Paul' )}
filter :contact, :as => :string, :collection => proc { (Contact.order.all).resources{|c| [c.name]}} 

注意:我的存储库可以找到here

型号:order.rb

belongs_to :contact

迁移:

def change
create_table :orders do |t|
  t.string :tag
  t.text :description
  t.string :technician_id
  t.string :status
  t.string :type
  t.string :contact_id
  t.string :business_id

  t.timestamps
end

admin / orders / - orders.rb

filter :business
filter :contact, :as => :string, :collection => proc { (Contact.order.all).resources{|c| [c.name]}}

filter :tag
filter :description, :label => "Status"
filter :created_at

index do   
  column :business
  column :contact
  column :tag
  column :status
  column :description, :sortable => false do |order|
  truncate(order.description, :length => 30)
end  

1 个答案:

答案 0 :(得分:3)

Activeadmin使用meta_search gem,所以试试这个:

filter :contact_name, :as => :string