3
문제는 다음과 같습니다. filter : contact, : as => : 연락처의 ID를 입력하면 string이 성공적으로 작동합니다. 하지만 2000 년 이상의 연락이있는 경우 실용적이지 않습니다. 어떻게하면 성공적으로 필터링 할 수 있습니다 : contact => : string하지만 : id 대신 : name을 찾습니다.Active_admin and :
는 나는 아무 성공 다음 시도 :
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