2013-08-30 87 views
0

我在form_for中使用了collection_select,但是瀏覽器中沒有顯示選項(空的選擇框),但出現在調試器視圖中。 (這發生在Chrome和IE10中)。Ruby on Rails - form_for collection_select選項不可見

查看:

<%= form_for(@lot) do |f| %> 
<%= f.label :client_id, "Client" %> 
<%= f.select :client_id, collection_select(:lot, :client_id, Client.all, :id, :org, :include_blank => "Please select") %> 

渲染頁面的源代碼:

<label for="lot_client_id">Client</label> 
<select id="lot_client_id" name="lot[client_id]"></select> 
<option value="">Please select</option> 
<option selected="selected" value="1">Client 1</option> 
<option value="2">client 2</option> 

控制器:

def new 
    @lot = Lot.new(:client_id => 1) 
end 

任何有識之士將不勝感激,謝謝,

回答

0

collection_select也是各種各樣的formHelper返回既是選擇和選項的元素,嘗試:

<%= f.collection_select(:lot, :client_id, Client.all, :id, :org, :include_blank => "Please select") %>

代替

+0

謝謝,這部分解決了它。作爲@lot的形式,我還需要刪除:使其成爲<%= f.collection_select(:client_id,Client.all,:id,:org)%>: – user2732663

1

你可以試試這個爲例如。

<%= f.collection_select(:category_id, Category.all,:id,:name, :required=>true) %> 
0

正進行渲染選擇助手裏面collection_select幫手,這是錯的。你必須這樣做:

<%= f.collection_select(:client_id, Client.all, :id, :org, :include_blank => "Please select") %>