A series of objects need to be purchased in a single transaction, however each item must be a different transaction object due to relationship issues.
A confirmation action aims to list each of these items independently. The controller attempts to prepare parameters for viewing each transaction
<% @transactions.each do |transaction| %>
<%= params[:product_id][:product_id] %>
[...]
as follows:
@transactions = params[:product_ids].map do |product_id|
@transaction = Transaction.new
@inventories = Inventory.where(['product_id = ?', product_id]).all
@my_price = my_price
params[:product_id][:product_id] = product_id # sanity check
params[:product_id][:additional_info] = session[:additional_info]
params[:product_id][:rate] = @inventories.map(&@my_price).inject(0, :+)
end
@sub_total = @transactions.params[:product_id][:rate].sum
However undefined method []= for nil:NilClass is generated when building the params for each product_id. This command is obviously mistaken. [The approach could also be inefficient/ineffective...]