2012-07-12 41 views
1

我有一個帶有輸入字段和下拉框的表單,其中包含來自其他表的數據。 (連接) 但現在,當我提出這是件好事,但是當我想編輯的字段下拉字段爲空,但文本字段不單擊編輯後,Rails 3.2沒有在表單中保存下拉選擇

我的表單代碼:

<%= form_for @contracten, :html => { :multipart => true } do |f| %> 
    <% if @contracten.errors.any? %> 
    <div id="error_explanation"> 
     <h2><%= pluralize(@contracten.errors.count, "error") %> prohibited this contracten from being saved:</h2> 

     <ul> 
     <% @contracten.errors.full_messages.each do |msg| %> 
     <li><%= msg %></li> 
     <% end %> 
     </ul> 
    </div> 
    <% end %> 
    <div id="forms"> 
    <div class="field"> 
    <%= f.label :naam %><br /> 
    <%= f.text_field :naam %> 
    </div> 
    <br> 
    <div class="field"> 
    <%= f.label :omschrijving %><br /> 
    <%= f.text_area :omschrijving %> 
    </div> 
    <br> 
    <div class="field"> 
    <%= f.label :organisatie %><br /> 
    <%= f.select :organisatieid, options_for_select(@organisaties.map{ |f| [f.naam, f.id] }), :include_blank => true %> 
    </div> 
    <br> 
    <div class="field"> 
    <%= f.label :vestiging %><br /> 
    <%= f.select :vestigingid, options_for_select(@vestigingens.map{ |f| [f.naam, f.id] }), :include_blank => true %> 
    </div> 
    <br> 
    <div class="field"> 
    <%= f.label :Beheerder %><br /> 
    <%= f.select :persoonid, options_for_select(@personen.map{ |f| [f.naam, f.id] }), :include_blank => true %> 
    </div> 
    <br> 
    <div class="field"> 
    <%= f.label :contractsoort %><br /> 
    <%= f.select :contractsoortid, options_for_select(@contractsoorten.map{ |f| [f.naam, f.id] }), :include_blank => true %> 
    </div> 
    <br> 
    <div class="field"> 
    <%= f.label :datumingang %><br /> 
    <%= f.datetime_select :datumingang %> 
    </div> 
    <br> 
    <div class="field"> 
    <%= f.label :datumeinde %><br /> 
    <%= f.datetime_select :datumeinde %> 
    </div> 
    <br> 
    <div class="field"> 
    <%= f.label :contractduur %><br /> 
    <%= f.number_field :contractduur, :placeholder => 'in jaren' %> 
    </div> 
    <br> 
    <div class="field"> 
    <%= f.label :opzegtermijn %><br /> 
    <%= f.number_field :opzegtermijn, :placeholder => 'In Maanden' %> 
    </div> 
    <br> 
    <div class="field"> 
    <%= f.label :betalingsperiode_eenheid_id %><br> 
    <%= f.select :betalingsperiodeeenheidid, options_for_select(@betalingsperiodeeenhedens.map{ |f| [f.omschrijving, f.id] }), :include_blank => true %> 
    </div> 
    <br> 
    <div class="field"> 
    <%= f.label :betalingstermijn %><br /> 
    <%= f.number_field :betalingstermijn %> 
    </div> 
    <br> 
    <div class="field"> 
    <%= f.label :pdf %><br /> 
    <%= f.file_field :pdf %> 
    </div> 
    <br> 
    <div class="actions"> 
    <%= f.submit "Toevoegen", :class => 'button3' %> 
    </div> 
    </div> 
<% end %> 
<br> 

截圖: form with dropdowns and textareas

我希望有人知道是什麼問題。

+0

請包括表單的代碼。此外,請確保表單域中的名稱匹配列名... – gabrielhilal 2012-07-12 11:42:27

+0

editted我的問題與_form.html.erb對不起,我忘了:) – 2012-07-12 11:51:32

+0

你有organisatieid,organisatieid,persoonid,contractsoortid數據庫中的同名嗎? – 2012-07-12 11:59:46

回答

4

:selected => ...添加到您的options_for_select參數中。

E.g:

<%= f.select :contractsoortid, 
      options_from_collection_for_select(@contractsoorten, 'id', 'naam', 
               :selected => @contracten.contractsortid), 
      :include_blank => true %> 

的變化實際上是保存,但是當你呈現形式,必須指定實際選擇的值。

+0

魔法。 :)無論如何,我更新使用'options_from_collectio_for_select',它比上一個更「軌道」。 – Matzi 2012-07-12 12:08:39

+0

嗯,不起作用我得到的錯誤錯誤數量的參數(1爲3) – 2012-07-12 12:13:19

+0

您可能留下了一個右括號,因爲沒有函數被調用1參數。 – Matzi 2012-07-12 12:16:19

相關問題