У меня проблемы с получением форм для ассоциации has_many для работы в корзине покупок. Представление отображает корзину и имеет строку таблицы для каждого элемента. Каждая строка содержит текстовое поле, чтобы пользователь мог установить количество.
Проблема в том, что в параметрах пропускается только количество строк первого элемента, даже если количество второго элемента тоже изменилось.
Может кто-нибудь помочь, пожалуйста?
Спасибо,
Roger
Ниже приведен вывод параметров в отладчике, через который пропускается только один элемент line_item.
(rdb:2624) e params
{"commit"=>"Recalculate",
"authenticity_token"=>"7TKnhmbBPFiKLzVqTipzH8PDyCrOnKiFixGQ37XDGNY=",
"_method"=>"put", "utf8"=>"✓", "action"=>"update", "id"=>"4",
"line_item"=>{"quantity"=>"3", "id"=>"6"}, "controller"=>"baskets"}
приложение / контроллеры / basket_controller.rb
class BasketsController < ApplicationController
def update
begin
@basket = Basket.find(params[:id])
# Can't do anything here yet since the correct parameters aren't being passed through.
rescue ActiveRecord::RecordNotFound
logger.error "..."
end
redirect_to basket_path
end
end
приложение / просмотров / корзины / show.html.erb
<%= form_for @basket do |f| %>
<table id="items">
<thead>
<tr>
<th>Name</th>
<th>Quantity</th>
<th>Price</th>
<th></th>
</tr>
</thead>
<tbody>
<% @basket.line_items.each do |item| %>
<%= form_for item do |g| %>
<tr class="<%= cycle('alternate', '') %>">
<td><%= item.product.name %></td>
<td>
<span class="decrement-quantity"><b>-</b></span>
<%= g.text_field :quantity %>
<span class="increment-quantity"><b>+</b></span>
</td>
<td class="price"><%= number_to_currency(item.total_price) %></td>
</tr>
<% end %>
<% end %>
<tr class="totals">
<td>Total</td>
<td><%= @basket.total_quantity %></td>
<td class="price"><%= number_to_currency(@basket.total_price) %></td>
<td></td>
</tr>
</tbody>
</table>
<%= f.submit 'Recalculate' %>
<% end %>