Filter Page Results By Column Value In Rails

Posted By Weston Ganger

<p>My posts have a categories, I wanted to filter the index page results for specific categories. Here is how to do it</p>
<p>The View:</p>

def index
  if params[:category_id]
    @posts = Post.where(:category_id => params[:category_id])
  else
    @posts = Post.all
  end
end

Article Topic:Software Development - Ruby / Rails

Date:July 03, 2014