繁体   English   中英

将Bootstrap表单帮助程序合并到simple_form中

[英]Incorporating Bootstrap Form Helpers into simple_form

我正在尝试使用国家/地区实现选择菜单,然后在选择国家/地区后使用状态过滤选择菜单。

我使用SimpleForm和Bootstrap,因此以下内容似乎非常适合我: http : //vincentlamanna.com/BootstrapFormHelpers/state.html

我目前将country_select gem与SimpleForm一起使用,并且我的代码包含:

<%= f.input :country, :id => "business_country", :input_html => { :class => "span6" } %>
<%= f.input :state, :input_html => { :class => "span6" } %>

当我包含相关的js文件并包含Bootstrap Form Helpers的默认示例代码时,此行为将按预期进行,但我希望将其包含在SimpleForm中,以便将其保存到数据库中。 这是正确执行的默认示例代码:

<select id="countries_states1" class="input-medium bfh-countries" data-country="US"></select>
<select class="input-medium bfh-states" data-country="countries_states1"></select>

有人可以建议如何实现此功能吗?

谢谢。

您是否遵循simple_form gem自述文件上的指示进行安装以支持Bootstrap? https://github.com/plataformatec/simple_form#twitter-bootstrap

rails generate simple_form:install --bootstrap

通过找到正确的国家选择(我在原始问题中的代码中看到的business_country)的正确ID,然后将数据国家添加到SimpleForm的input_html中以选择国家,我可以使其工作。 编码:

<%= f.input :country, :input_html => { :class => "span6 input-medium bfh-countries"} %>
<%= f.input :state, as: :select, :input_html => {:class => "span6 input-medium bfh-states", 'data-country' => ('business_country') } %>

暂无
暂无

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

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