sending multiple parameters on checkbox submit rails -
i'm having trouble getting multiple parameters submitted when use checkbox submit. how send both parameters?
i have 2 items in each row in table, columns "product revenue" , "product title" , use check box on each row select , on submit i'd send both of these values controller. can 1 item working, wasn't able figure out how send second item tried using hidden field, couldn't working.
view code
<%= form_tag add_multiple_path, method: :post %> <%= 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 1 item @ 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 |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"}
to original question (before correction), you're missing =
here:
<% hidden_field_tag('price_test_datum[product_price][]', p.metrics[0].values[0]) %>
it should be:
<%= hidden_field_tag('price_test_datum[product_price][]', p.metrics[0].values[0]) %>
Comments
Post a Comment