2015-04-18 48 views
0

所以我使用Rails 3.2.11的nested_form(根據Gemfile.lock的v0.3.2)。我有一個帶有類別字段的服務模型,最初可以採用多個可通過選擇下拉列表輸入的值。什麼可能導致nested_form不輸出正確的選定輸入值?

類別是這樣的:[「Ĵ獎」,「Z獎」,「其他」]

當我去保存表單字段爲J獎(或Z獎)的值和重新呈現一個可編輯的表單,表單將重新顯示值爲「其他」的類別。然而,如果我走進軌道控制檯並查看保存的服務模型的類別字段,它會顯示「J Award」。

這可能是什麼原因造成的?由於nested_form不再維護,我應該放棄並以不同的方式處理多個模型?重新呈現形式的

HAML輸出

= semantic_nested_form_for @service, :url => "/update", :html => { :class => "service", :autocomplete => "off" } do |f| 
    %h1.page-title Service 
    .page-wrapper 
    = render :partial => "shared/error_messages", :locals => { :object => @service } 

重新呈現形式的HTML輸出:

<li class="string input required stringish" id="service_category_input"><label class=" label" for="service_category">Category<abbr title="required">*</abbr></label><input id="service_category" maxlength="255" name="service[category]" type="text" value="J Award" /> 

     </li> 

    = f.inputs do 
     %h3 Project Information 
     = f.input :billable, :as => :radio, :collection => { 'Billable' => true, 'Non-billable' => false }, :label => 'Category', :input_html => { :disabled => true } 
     = f.input :category 
     = f.input :assigned_consultant, :input_html => { :readonly => true } 
     = f.input :aims, :input_html => { :readonly => true } 

回答

1

在你html.erb文件,我會改變的f.inputf.select

<%= f.select :category, ["J Award", "Z Award", "Other"], {selected: f.object.category} %> 

selected屬性是不言自明的。我以前從來沒有使用過.haml文件,所以我想你必須以某種方式將其轉換。

相關問題