【问题标题】:Adding html options to ransack predicate_select将 html 选项添加到 ransack predicate_select
【发布时间】:2023-03-09 23:47:01
【问题描述】:

我正在使用带有 rails 4 应用程序的 ransack gem,并希望将引导类合并到 search_form_for 中。这是我的选择目前的样子。

<%= c.predicate_select ({only: [:cont, :not_cont, :eq, :not_eq, :blank, :null, :not_null]})%>

我也尝试过使用像这样的 html 选项传入第二个哈希(根据文档):

 <%= c.predicate_select ({only: [:cont, :not_cont, :eq, :not_eq, :blank, :null, :not_null]},{class=>'form-control'})%>

显然我做错了什么。 有人对如何正确地将类应用于 ransack predicate_select 有任何建议吗?

【问题讨论】:

    标签: ruby-on-rails ransack


    【解决方案1】:

    这很奇怪。当我打电话时

    <%= c.predicate_select({only: [:cont, :not_cont]}, {class: 'my_class'}
    

    我明白了

    <select class="my_class" id="q_p" name="q[p]" style="display: none;">...</select>
    

    您的代码示例中有错字 (...,{class=&gt;'form_control'}),但我怀疑这不是导致此问题的原因?

    【讨论】:

    • 感谢您的回复!它实际上只是我错误地在 "select" 和 "({onl​​y" 之间留下的空间正确的语法是: 再次感谢!