W
W
weare1382015-03-10 19:38:40
Ruby on Rails
weare138, 2015-03-10 19:38:40

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

and the view itself
.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

2 answer(s)
E
Eugene Burmakin, 2015-03-11
@Freika

Can you make scopes and make links to these scopes?

D
dzivalli, 2015-03-12
@dzivalli

Ajax?
I chose a category, sent a request to the server, it sent json with all the posts in this category, and did you render them?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question