Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails how can I pass multiple values through check_box_tag?

I am trying to pass multiple values to a custom function that I created through the check_box_tag, however I don't really know how to do it, I have check online for hours but didn't help.

Basically I have a details view, and I try to pass the date and id information of the detail to the controller and call the create method.

<%= form_tag( { :action => 'create' } ) do %>
    <%  @details.each do |detail| %>
    <%= check_box_tag 'date[]', detail.date, false, :id => detail.id %>

        <%= detail.date %> 
    <% end %>
    <%= submit_tag 'Register!' %>
<% end %>

I try to set the custom value but when I type params in the debugger this is what it shows

{"utf8"=>"✓", "authenticity_token"=>"3PKBBKNmXyAfdSllTWBFP8EafhbrJ8rCgOeOp2NbeBA=", "date"=>["2013-06-08"], "commit"=>"Register!", "action"=>"create", "controller"=>"line_items"}

I really don't know how should I do it.

Thank you for your answer in advance!

like image 728
Cheng Lun Chen Avatar asked Feb 16 '23 18:02

Cheng Lun Chen


1 Answers

please using array dates.

<%= form_tag( { :action => 'create' } ) do %>
    <%  @details.each do |detail| %>
    <%= check_box_tag 'detail[dates][]', detail.date, false, :id => detail.id %>
        <%= detail.date %> 
    <% end %>
    <%= submit_tag 'Register!' %>
<% end %>
like image 102
akbarbin Avatar answered Mar 27 '23 21:03

akbarbin