This is probably very simple to do, but I am having trouble wrapping my head around it. I have a model called "document" and a field within the model called: category.
Category can consist of 3 options:
- Meeting Notes
- Sales
- Engineering
In my view I have: [index.html.erb]
<% @documents.each do |document| %>
<div class="table-div">
<div class="col-sm-12 col-md-12 div-table-label">
<strong><%= document.category %></strong>
</div>
<div class="col-sm-12 col-md-12">
<%= link_to document.title, document %>
</div>
</div>
<% end %>
In my controller, just the default:
def index
@documents = Document.all
end
What I want to do is loop through each category and grab all documents tied to that category to group them together.
Right now, it just prints each document with its category heading in the order it is created, no logic to it at all.
Thanks.