Reputation: 2520
I have three rows of checkboxes on frontend side
when I check some values and then pass on the parameters to controller, they look like numbers. For example,
"service_attributes"=>{"id"=>1, "simplicity"=>"1", "convenience"=>"3", "atmosphere"=>"5"}
Every time I change a value on any of the row, the record gets updated, however when I uncheck options, params are not being passed
"service_attributes"=>{"id"=>1}
and nothing happens. The record remains with old values.
How can I do so that when I uncheck the checkboxes, the record is supposed to update with 0 values. Like the following:
<Service id: 1, simplicity: 0, convenience: 0, atmosphere: 2, user_id: 1>
Upvotes: 0
Views: 639
Reputation: 2411
You need to add another field that will pass the value false to your controller.
<input name="service_attributes[simplicity]" type="hidden" value="0" />
<input checked="checked" type="checkbox" id="service_attributes_ simplicity" name="service_attributes[simplicity]" value="1" />
Or you could simply use the checkbox_helper.
Upvotes: 1