Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 简单表单关联输入:按条件限制选项_Ruby On Rails_Simple Form - Fatal编程技术网

Ruby on rails 简单表单关联输入:按条件限制选项

Ruby on rails 简单表单关联输入:按条件限制选项,ruby-on-rails,simple-form,Ruby On Rails,Simple Form,我有一个带有代码的简单表格: <%= simple_form_for @business, :html => {:class => "form-inline"} do |f| %> <%= f.association :business_type, :as => :collection_select, :input_html => {:class => "input-small"}, :label => "Type of Business"%

我有一个带有代码的简单表格:

<%= simple_form_for @business, :html => {:class => "form-inline"} do |f| %>
<%= f.association :business_type, :as => :collection_select, :input_html => {:class => "input-small"}, :label => "Type of Business"%>
<%= f.button :submit, :class => "primary pull-left" %>
<% end %>
{:class=>“表单内联”}do | f |%>
:collection_select,:input_html=>{:class=>“input small”},:label=>“业务类型”%>
“主向左拉”%>
业务类型
模型中,我有以下几层:第一层、第二层、第三层

我希望选择允许用户选择
业务类型
模型中的所有选项,第一层选项除外,但无法使其工作


谢谢。

您可以使用以下方法限制收集选项:

f.association :business_type, :as => :collection_select, collection: BusinessType.where('biztype <>?', 1), :input_html => {:class => "input-small"}, :label => "Type of Business"
f.association:business\u type,:as=>:collection\u select,collection:BusinessType.where('biztype?',1),:input\u html=>{:class=>“input small”},:label=>“业务类型”
我不知道你用什么变量来定义层,但不管这个变量是什么,只要在它不等于第一层时寻找,就可以限制业务类型选项。可以在文档中找到