简体   繁体   English

带有文本字段的活动admin habtm过滤器

[英]Active admin habtm filter with text field

I have an association 我有一个协会

  class School < ActiveRecord::Base
    has_and_belongs_to_many :standards
  end

In my active admin page for standards, I need to have a filter for schools with a text field for typing the school id. 在我的标准活动管理页面中,我需要为学校提供一个过滤器,并使用文本字段输入学校ID。 (Having a dropdown as schools filter is not feasible since I've thousands of schools in my db). (因为我的数据库中有成千上万的学校,所以在下拉列表中添加学校过滤是不可行的)。 I need something like: 我需要类似的东西:

  filter :schools_id

Please help 请帮忙

Have you tried this gem? 你试过这个宝石吗? I love it. 我喜欢它。 https://github.com/holyketzer/activeadmin-ajax_filter https://github.com/holyketzer/activeadmin-ajax_filter

If what you want is to filter the standards index by schools, supposing your model association is bidirectional you can install the gem and try something like this: 如果您想要按学校过滤标准索引,假设您的模型关联是双向的,则可以安装gem并尝试执行以下操作:

  include ActiveAdmin::AjaxFilter
  filter :school, as: :ajax_select, data: {
    url: '/admin/schools',
    search_fields: [:id],
    static_ransack: { active_eq: true },
    ajax_search_fields: [:id], 
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM