2013-08-30 88 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") %>