Answer the question
In order to leave comments, you need to log in
How to send the parent_id of the selected sub_category when submitting the form?
There are categories and there are sub-categories, there is a parent_id in the table
There is a form, when sending it to the join table, the IDs of the selected sub-categories go to the join table, and you also need to leave the parent ID of the category as a steam locomotive, how to do this?
<%= hidden_field_tag "user[ecategory_ids][]", nil %>
<% Category.where(parent_id: 0).each do |category| %>
<%= label_tag dom_id(category), category.name %>
<% Сategory.where(parent_id: category.id).each do |category| %>
<%= label_tag dom_id(ecategory), ecategory.name %>
<%= check_box_tag "user[ecategory_ids][]", ecategory.id, @user.category_ids.include?(category.id), id: dom_id(category) %>
<%= f.submit "Сохранить" %>
<% end %>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question