tested 这是一个 boolean
tested
boolean
checkbox 用户可以在其中基于 测试 .
checkbox
测试
filterrific :default_filter_params => { :sorted_by => 'created_at_desc' }, :available_filters => %w[ sorted_by search_query with_created_at_gte with_tested ] scope :with_tested, lambda { |flag| return nil if 0 == flag # checkbox unchecked where(tested: true) } /// Other scopes
在我看来,我有:
= f.check_box :with_tested
在我的模型中,我也尝试过不同的方法,但没有运气:
scope :with_tested, lambda { |value| where('posts.tested = ?', value) } // and scope :with_tested, lambda { |query| return nil if 0 == query # checkbox unchecked where('posts.tested == ?', query) } // and scope :with_tested, lambda { |flag| return nil if 0 == flag # checkbox unchecked where(tested: [flag]) }
测试 ,我可以看到我的过滤器正在尝试过滤 (我看到过滤器旋转) ,但未正确筛选我的记录。
我不确定我做错了什么。任何建议和帮助都将不胜感激!
附言:我还没有补充 with_tested 在我的控制器里,因为我知道我不需要它
with_tested
版本:
RubyonRails:4.2.4
过滤系数:2.1.2
问题是 where(tested: [flag]) ,因为还没有 设置 到 true 或 false where 应该 怎么回事 value 在 那个案子
where(tested: [flag])
true
false
where
value
所以呢 应更改为: where(tested: true) 或 where(tested: false) .
where(tested: true)
where(tested: false)
首先,您需要在 model :
model
scope :with_tested, lambda { |flag| return nil if 0 == flag # checkbox unchecked where(tested: true) }
在你的 view
view
并添加 :with_tested 在你的控制器里 available_filters .
:with_tested
available_filters