D
D
dexdev2014-10-16 16:54:58
Ruby on Rails
dexdev, 2014-10-16 16:54:58

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

1 answer(s)
O
Oleg S, 2014-10-16
@qazwsx

parent_id is better defined and assigned in the controller, not added to the form

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question