问题在于如下内容:如果我输入联系人的ID,则过滤器:contact,:as => :string可以成功运行。但是当你有2000多个联系人时,这种方法就不太实用了。我该如何成功地使用过滤器:contact, as => :string,但是搜索名字而不是ID呢?
我尝试了以下方法但没有成功:
注意:我的代码库可以在这里找到。
我尝试了以下方法但没有成功:
filter :contact, :as => :string, :collection => proc {Contact.where(:name => 'Paul' )}
filter :contact, :as => :string, :collection => proc { (Contact.order.all).resources{|c| [c.name]}}
注意:我的代码库可以在这里找到。
模型: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
结束
管理员/订单/ - 订单.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