2

我想实现一个选择菜单,国家,一旦某个国家被选中,然后过滤与状态一个选择菜单。结合引导表单he​​lper到simple_form

我用SimpleForm和Bootstrap所以下面似乎适合我的完美:http://vincentlamanna.com/BootstrapFormHelpers/state.html

我目前使用的country_select宝石与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> 

任何人都可以建议如何实现这是SimpleForm?

谢谢。

回答

0

我把它通过发现我国正确的ID选择(business_country如我在我原来的问题代码所示),并添加数据,国家对input_html在SimpleForm的状态下工作选择。代码:

<%= 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') } %> 
0

是否按照simple_form gem自述文件中的说明安装了Bootstrap支持? https://github.com/plataformatec/simple_form#twitter-bootstrap

rails generate simple_form:install --bootstrap

+0

是的。对不起,我忘了提到这一点。我相信我的主要问题是如何将'data-country =“countries_states1”'纳入我的简单字段。也许像':input_html => {“data-remote”=> true',但我不太确定要使用什么。 – Marklar 2013-05-14 03:22:04