2013-03-05 34 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