點擊 「添加項目」,添加兩個 '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' ...... 幫我:)))