4 Categories for blog post
I created a rails blog and added categories to label the blog type. In the header I have
<% Category.all.each do |category| %>
<li><%= link_to category.name, posts_path(category: category.name) %></li>
<% end %>
If someone clicks one of the 4 categories( eat, drink, travel,news) then it populates that category on the index page. However, prior to clicking is there a way to organize the blog posts by category. I'm trying to replicate the blog after http://blog.airbnb.com/ with each category having it's own box. What would be the code for that?
Right now on the index page I just run a loop and it just displays all types vertically. Is this a css/html issue or controller issue?
<div class="row" >
<% @posts.each do |post| %>
<div class="box panel panel-default">
<%= link_to image_tag(post.image.url), post %>
<h5><%= post.category.name %></h5>
<h6><%= post.title %></h6>
<% end %>
Posted almost 5 years ago by