I have Post
and category
models
Post
belongs_to :category
Category
has_many :posts
On a category show page, I’m able to display a list of all posts which belongs to this category by
<% Post.where(category_id: @category.id).each do |post| %>
....
<% end %>
categories_controller ....
def show
@category = Category.friendly.find(params[:id])
@categories = Category.all
end
How can I display a list of related posts which belongs to the same category (or sharing the same category id), on one of the post’s show page. Thanks!