[Newbie] Filtering Index page

Hello all and thank you for your time and help.

I am working on my first big project and one of the requests that I have is to host a directory list people, with the option to click from an array of buttons with the different position titles. Button examples being: Staff, Faculty, Grad Student, etc. I have the index listing the full directory currently, but I was hoping someone would be willing to point in a direction to look for examples of how to set this up, or a gem that might be beneficial. I am researching on my own, but I do not feel I am finding quite what I am seeking.

Thanks again for any help!


Hi, Jason, welcome!

As you’re building out your skills, I would refrain from looking for a gem for this sort of functionality, as it’s a good thing to learn in general how to do.

You can do this pretty easily if you only want to allow one position at a time:

<%= link_to “Staff”, people_path(:filter_by => :staff), {:method => :get}, {:class => “button”} %>

for example, with one of these corresponding to each of the positions. You’ll need to create a CSS class for .button to make the link look like a button.

On your PeopleController#index method, you’ll need to check for a filter_by parameter:

def index

if params[:filter_by]

@people = Person.where(:position => params[:filter_by])


@people = Person.all


… and whatever else you need to do to prepare for the view…


If you want to allow the user to select multiple of these, you’ll need a form with checkboxes or a multi-select.

I hope that’s enough of a start.

Thank you for the welcome and the response!

What have given me works great! With the exception of the {:class => “button”} which throws up a wrong number of arguments (4 for 0…3) error. I am looking into this to see if I can find out more. I tried this also with the button_to which makes the button but does not do the filtering. More and more stuff to research.

Thank you again for your help!