2013-03-05 38 views
3

限制选项我有一个简单的形式与所述代码:简单形式的关联输入:由条件

<%= 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 %> 

business type模型中,我有以下:first_tier,second_tier,third_tier。

我希望选择允许用户选择business type模型中的所有选项,除first_tier选项外,但无法使其工作。

谢谢。

回答

5

您可以使用此限制收集选项:

f.association :business_type, :as => :collection_select, collection: BusinessType.where('biztype <>?', 1), :input_html => {:class => "input-small"}, :label => "Type of Business" 

林不知道你用的是什么变量定义层,但无论该变量只是寻找,当它不等于first_tier限制的业务类型选项。 MORE INFO可以在文档中找到。

+0

刚刚用compare语句编辑了你的答案。 – noob 2013-03-06 23:06:13