如何按各自的部分对类别进行排序?
就像“语言”部分有英语、阿拉伯语、西班牙语等一样。我想将部分名称显示为标题,并将它们的类别显示为复选框。这是我的代码。
应用程序/模型/profile.rb
class Profile < ActiveRecord::Base
has_many :categorizations
has_many :categories, through: :categorizations
end
应用程序/模型/category.rb
class category < ActiveRecord::Base
belongs_to :section
has_many :categorizations
has_many :profiles, through: :categorizations
end
应用程序/模型/section.rb
class Section < ActiveRecord::Base
has_many :categories
end
app/views/profiles/_form.html.rb
<div class="field">
<%= hidden_field_tag "profile[category_ids][]", nil %>
<% Category.all.each do |category| %>
<%= check_box_tag "profile[category_ids][]", category.id, @profile.category_ids.include?(category.id), id: dom_id(category) %>
<%= label_tag dom_id(category), category.name %><br>
<% end %>
</div>