Reputation: 281
How can I pass a Array values to check box I have an Array say loan["1","2","3"] and in my view
<%= check_box_tag "loan[]" ,c.id , true %>
For the first time i select the ids and Ill save. But at the second time only selected ids(which i have selected for the first time) should be displayed and rest should be unchecked. Thanks in advance
Upvotes: 0
Views: 37
Reputation: 2597
You must pass two arrays into view - all loans and checked loans.
And in 3rd check_box_tag
parameter check their interseption, something like this:
<% @loans.each do |loan| %>
<%= check_box_tag "loans[]", loan.id, @checked_loans.any? { |checked_loan| checked_loan.loan_id == loan.id } %>
<% end %>
Upvotes: 3