Domanda

Il problema risiede nel seguente: Filtro: Contatto ,: As =>: String funziona correttamente se digio l'ID per il contatto. Ma non è pratico quando hai oltre 2000 contatti. Come posso filtrare correttamente: contattare, as =>: stringa ma cercarlo: nome anziché: id.

Ho provato quanto segue senza successo:

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

Nota: il mio repository può essere trovato qui.

Modello: order.rb

belongs_to :contact

Migrazione:

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

fine

Amministratore/ Ordini/ - ordini.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  
È stato utile?

Soluzione

ActivEADmin usa Meta_Search Gem, quindi prova questo:

filter :contact_name, :as => :string
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top