Answer the question
In order to leave comments, you need to log in
How to implement search by category?
Hi guys, this is a question: there are two post and category models, a habtm connection. Question: how to make a list of all posts be rendered on the main page, and a list of categories on the right. and you click on a category, and it returns a selection of posts in the same action by these categories
action index
def index
@categories = Category.all
@posts = Post.all
end
.col-md-8
- @posts.each do |post|
h2 = link_to post.title, post_path(post)
= post.description
p = sanitize post.body
.col-md-4
- @categories.each do |category|
h4 = link_to category.name
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question