I've got a loop that looks like this:
<% current_user.brand.templates.each do |template| %>
<li><%= link_to(template.label, new_templated_document_path(template)) %></li>
<% end %>
A Template
can have a category, but it's just a string and not an association. Is there a way to collect the Templates
here based on category and sub-menu them accordingly? It feels like I'll have to build an array for each category in the model or something. Something like this:
categories = []
Template.categories.each do |c|
category = []
category << Template.where(category: c).all
categories << category
end
categories
Feels pretty clumsy though. Any help?
Update
I've changed it to this:
@categories = {}
Template.first.categories.each do |c|
@categories[c] = current_user.brand.templates.where(category: c)
end
But I can't seem to get the records into the hash. Is that even possible?