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=>“业务类型”
我不知道你用什么变量来定义层,但不管这个变量是什么,只要在它不等于第一层时寻找,就可以限制业务类型选项。可以在文档中找到