簡體   English   中英

Ruby on Rails-form_for collection_select選項不可見

[英]Ruby on Rails - form_for collection_select options not visable

我在form_for中使用collection_select,但是選項未顯示在瀏覽器中(空選擇框),但出現在調試器視圖中。 (在chrome和IE10中都會發生這種情況)。

視圖:

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

任何見解將不勝感激,謝謝,

您可以嘗試例如。

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

collection_select還是一個同時返回select和options元素的formHelper ,請嘗試:

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

代替

您正在選擇幫助器內部呈現collection_select幫助器,這是錯誤的。 您必須這樣做:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM