I have a basic question about checkboxes in forms.
I have a simple form for user interests, which has two fields - id and interest_id
<%= simple_form_for (@user_interest) do |f| %>
<%= f.error_notification %>
<%= f.label :interest_id %><br>
<%=f.text_field :interest_id, class: 'form-control'%>
<%= check_box_tag :interest_id %>
<%= f.submit "Update my account", class: "btn btn-primary" %>
<% end %>
If I look at the resulting HTML
<input class="form-control" type="text" name="user_interest[interest_id]" id="user_interest_interest_id">
<input type="checkbox" name="interest_id" id="interest_id" value="1">
I am having difficuly understanding why the the name of the text_field (which works) is correct, but the name of the checkbox (which doesn't work) is "interest_id" (and not user_interest[interest_id]
Fully appreciate this is completely basic but actually, these very basic questions can be difficult to get answers to. Many thanks.
Aucun commentaire:
Enregistrer un commentaire