I'm having trouble getting multiple parameters to be submitted when I use a checkbox submit. How would I send both parameters?
I have two items in each row in a table, the columns are "product revenue" and "product title" and I use a check box on each row to select it and then on submit I'd like to send both of these values to the controller. I can get one item working, but wasn't able to figure out how to send the second item as well I tried using a hidden field, but I couldn't get that working.
View Code
<%= form_tag add_multiple_path, method: :post do %>
<%= check_box_tag 'price_test_datum[product_title][]', p.dimensions[0] %>
<% hidden_field_tag('price_test_datum[product_price][]', p.metrics[0].values[0]) %>
<%= submit_tag "Add selected" %>
<% end %>
Controller Code (only for one item at the moment since both params aren't being sent)
def add_multiple
params[:price_test_datum][:product_title].each {|p| PriceTestDatum.create(product_title: p) }
respond_to do |format|
format.html { redirect_to price_test_data_path }
format.json { head :no_content }
end
end
Parameters sent: {"utf8"=>"✓", "authenticity_token"=>"token here", "price_test_datum"=> {"product_title"=>["Widget 1", "Widget 2"]}, "commit"=>"Add selected"}
<%before yourhidden_field_tag. It seems lonely for an=.pvariable (where you sayp.metrics[0].values[0]).