Active_admin 和 :filter

发布于 2025-01-07 06:42:13 字数 1262 浏览 1 评论 0 原文

问题在于:filter :contact, :as =>如果我输入联系人的 ID,则 :string 会成功运行。但当您有 2000 多个联系人时,这就不太现实了。如何成功过滤 :contact,如 => :string 但让它搜索 :name 而不是 :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

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  

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  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

场罚期间 2025-01-14 06:42:13

Activeadmin 使用meta_search gem,所以试试这个:

filter :contact_name, :as => :string

Activeadmin uses meta_search gem, so try this:

filter :contact_name, :as => :string
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文