Scenario

You have a blog application and on the index page you have a list with all posts. A post belongs to a category so you want to have a dropdown to filter the posts per category.

The first thing we need to do is set a variable to hold the available categories:

class PostsController < ApplicationController
  def index
    @posts = Post.all
    @categories = Category.all
  end
end

Now we need a form with the dropdown to send the category_id that we want to filter:

= form_tag(posts_path, method: :get) do
  = select_tag "category_id", options_for_select(@categories.map{ |c| [c.name, c.id]}), { prompt: 'Select category', onchange: 'this.form.submit();' }

If we select a category, it will send the category_id in the params to the PostsController Index action.
The last step is to modify this action to display the filtered posts:

class PostsController < ApplicationController
  def index
  if params[:category_id] && !params[:category_id].empty?
    @posts = Post.where(gategory_id: params[:category_id])
  else
    @posts = Post.all
  end
    @categories = Category.all
  end
end