mercredi 7 septembre 2016

Rails - checkbox to disable from inserting to database

I have my nested form with check_box_tags (for now)

<%= check_box_tag("place[open_days_attributes][0][day]", value = "monday", checked = false, options = {})%>
<%= text_field_tag("place[open_days_attributes][0][from_time]", value = nil, options = {})%>
<%= text_field_tag("place[open_days_attributes][0][to_time]", value = nil, options = {})%>
<%= check_box_tag("place[open_days_attributes][1][day]", value = "tuesday", checked = false, options = {})%>
<%= text_field_tag("place[open_days_attributes][1][from_time]", value = nil, options = {})%>
<%= text_field_tag("place[open_days_attributes][1][to_time]", value = nil, options = {})%>

And this goes on up to Sunday value of checkbox. Whenever I submit this form it inserts 7 (because we have 7 days in a week) object into my database. What I want to do is to submit only those with checked checkbox.

Is something like this possible? I couldn't find anything relative.




Aucun commentaire:

Enregistrer un commentaire