【问题标题】:ActiveAdmin filter boolean as single checkboxActiveAdmin 过滤布尔值作为单个复选框
【发布时间】:2012-07-25 09:48:36
【问题描述】:

如何使用单个复选框过滤布尔值?

例如,下面给了我两个带有yesno 值的复选框:

ActiveAdmin.register User do    
  filter :is_retired, :as => :check_boxes
end

HBTM 关联过滤如下:

filter :roles_id, :as => :check_boxes, :collection => proc { Role.all }

但我的User 模型中有一个布尔字段,需要一个带有Is retired 标签的复选框。有没有可能?

【问题讨论】:

  • IMO 这样做没有任何意义。如果选中该复选框,则表明您要搜索is_retiredTRUE 的位置;未选中时,您想搜索is_retiredFALSE 的位置。您永远无法使用单个复选框搜索TRUE FALSEstackoverflow.com/questions/7608788/…

标签: ruby-on-rails ruby ruby-on-rails-3 activeadmin


【解决方案1】:
filter :is_retired,
  as: :check_boxes,
  collection: [['Yes', true]],
  label: 'Retired?'

【讨论】:

    【解决方案2】:

    如建议elsewhere 使用 filter :enabled, as: :select, collection: [["Yes", true], ["No", false]]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-06
      • 1970-01-01
      • 2016-12-31
      • 1970-01-01
      • 1970-01-01
      • 2012-06-04
      相关资源
      最近更新 更多