如何使用 Ransack gem 在 Rails 中的 select_tag 中使用 *_in 谓词?
How to use *_in predicate in a select_tag in Rails using the Ransack gem?
我正在使用 Ransack gem,我需要一个包含 3 个选项的 select 选项下拉列表,但每个选项都有多个值。我假设我需要使用 *_in 谓词但是当我执行以下操作时:
<%= f.select :status_in, options_for_select([['Approved', 0], ['Pending Payroll', [1,3,5,7] ], ['Denied', [2,4,6,8] ]]), {include_blank: 'Any'}, {class: 'form-control input-sm'} %>
和selectPending Payroll or Denied,它只获取状态为0的对象。生成正确的(我认为)HTML:
<option value="0">Approved</option>
<option value="[1, 3, 5, 7]">Pending Payroll</option>
<option value="[2, 4, 6, 8]">Denied</option>
如有任何帮助,我们将不胜感激!
通过绕过 Ransack 解决。我创建了一个简单的 select_tag:
<%= select_tag :status_not_ransack, options_for_select(Request.select_options), {class: 'form-control input-sm'} %>
并且刚刚在我的控制器中执行了以下操作:
if params[:status_not_ransack]
case params[:status_not_ransack]
when '0'
@q.status_in = [0]
when '1'
@q.status_in = [1,3,5,7]
when '2'
@q.status_in = [2,4,6,8]
else
@q.status_in = ''
end
end
我正在使用 Ransack gem,我需要一个包含 3 个选项的 select 选项下拉列表,但每个选项都有多个值。我假设我需要使用 *_in 谓词但是当我执行以下操作时:
<%= f.select :status_in, options_for_select([['Approved', 0], ['Pending Payroll', [1,3,5,7] ], ['Denied', [2,4,6,8] ]]), {include_blank: 'Any'}, {class: 'form-control input-sm'} %>
和selectPending Payroll or Denied,它只获取状态为0的对象。生成正确的(我认为)HTML:
<option value="0">Approved</option>
<option value="[1, 3, 5, 7]">Pending Payroll</option>
<option value="[2, 4, 6, 8]">Denied</option>
如有任何帮助,我们将不胜感激!
通过绕过 Ransack 解决。我创建了一个简单的 select_tag:
<%= select_tag :status_not_ransack, options_for_select(Request.select_options), {class: 'form-control input-sm'} %>
并且刚刚在我的控制器中执行了以下操作:
if params[:status_not_ransack]
case params[:status_not_ransack]
when '0'
@q.status_in = [0]
when '1'
@q.status_in = [1,3,5,7]
when '2'
@q.status_in = [2,4,6,8]
else
@q.status_in = ''
end
end