سؤال

The issue lies in the following: filter :contact, :as => :string works successfully if I type the id for the contact. But that's not practical when you have 2000+ contacts. How can I successfully filter :contact, as => :string but have it search for :name instead of :id.

I have tried the following with no success:

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

Note: my repository can be found here.

Model: order.rb

belongs_to :contact

Migration:

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

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  
هل كانت مفيدة؟

المحلول

Activeadmin uses meta_search gem, so try this:

filter :contact_name, :as => :string
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top