3
問題在於:filter:contact,:as =>:如果我輸入聯繫人的ID,則字符串可以成功工作。但是當你有2000多個聯繫人時,這是不實際的。我怎樣才能成功地過濾:contact,as =>:string,但要搜索:name而不是:id。Active_admin和:filter
我曾嘗試沒有成功如下:
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
末
管理員/命令/ - 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