Question

Les mensonges de question dans les domaines suivants: filtre: contact,: as =>: chaîne fonctionne avec succès si je tape l'identifiant du contact. Mais ce n'est pas pratique quand vous avez des contacts 2000+. Comment puis-je filtrer avec succès: le contact, comme =>: chaîne, mais l'ont chercher: nom au lieu de: id.

J'ai essayé ce qui suit sans succès:

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

Note: mon dépôt se trouve

.

Modèle: 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 / commandes / - 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  
Était-ce utile?

La solution

Activeadmin utilise gemme meta_search, alors essayez ceci:

filter :contact_name, :as => :string
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top