2014-11-14 78 views
0

點擊 「添加項目」,添加兩個 'fields_for:項目' 嵌套形式(場)nested_form寶石軌道4顯示了點擊兩個嵌套形式(場)link_to_add

需要幫助:)))

Assosiation:

菜單(的has_many:項目), 項目(belongs_to的:菜單)

<%= nested_form_for(@menu) do |f| %> 
    <div class="form-group"> 
    <%= f.label :title %><br> 
    <%= f.text_field :title, :class=>"form-control", :placeholder => "Title" %> 
    </div> 

    <div class="form-group"> 
    <%= f.label :description %><br> 
    <%= f.text_area :description, :class=>"form-control", :placeholder => "Description" %> 
    </div> 

    <h3>Items</h3> 
    <%= f.fields_for :items do |i| %> 

    <div class="form-group"> 
    <%= i.label :name %><br>  
    <%= i.text_field :name, :class=>"form-control", :placeholder => "Name" %> 
    </div> 

    <div class="form-group"> 
    <%= i.label :price %><br> 
    <%= i.text_field :price, :class=>"form-control", :placeholder => "Price" %> 
    </div> 

    <div class="form-group"> 
    <%= i.label :description %><br> 
    <%= i.text_area :description, :class=>"form-control", :placeholder => "Description" %> 
    </div> 

    <%= i.link_to_remove "Remove this item", :class=>"btn btn-default" %> 
    <% end %> 

    <p><%= f.link_to_add "Add an Item", :items, :class=>"btn btn-default" %></p> 

    <%= f.hidden_field :restaurant_id, :value => params[:restauranti_id]`enter code here` 

    <div class="actions"> 
    <%= f.submit 'Create Menu', :class=>"btn btn-default" %> 
    </div> 
<% end %> 

添加這兩次:

<%= f.fields_for :items do |i| %> 

    <div class="form-group"> 
    <%= i.label :name %><br>  
    <%= i.text_field :name, :class=>"form-control", :placeholder => "Name" %> 
    </div> 

    <div class="form-group"> 
    <%= i.label :price %><br> 
    <%= i.text_field :price, :class=>"form-control", :placeholder => "Price" %> 
    </div> 

    <div class="form-group"> 
    <%= i.label :description %><br> 
    <%= i.text_area :description, :class=>"form-control", :placeholder => "Description" %> 
    </div> 

    <%= i.link_to_remove "Remove this item", :class=>"btn btn-default" %> 
    <% end %> 

我現在的版本是 '軌道', '4.1.6' ...... 幫我:)))

回答

0

我有同樣的問題。宓解決方案是未來:

在文件app/views/layouts/application.html.erb我有一個代碼

<!DOCTYPE html> 
<html> 
<head> 
    <title>RoR 1</title> 
    <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> 
    <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> 

    <%= stylesheet_link_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/redmond/jquery-ui.css", "application" %> 
    <%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js", "application" %> 
    <%= csrf_meta_tags %> 

</head> 
<body> 
    <div class="container"> 
    <%= yield %> 
    </div> 

</body> 
</html> 

然後我刪除此代碼

<%= stylesheet_link_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/redmond/jquery-ui.css", "application" %> 
<%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js", "application" %> 

而且我解決了這個問題。

1

刪除<%= javascript_include_tag:默認值,在佈局 「nested_form」 %> (: