[Newbie] Filtering Index page

19 views
Skip to first unread message

Jason O

unread,
Feb 9, 2015, 3:18:16 PM2/9/15
to rubyonra...@googlegroups.com
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!

Jason

tamouse pontiki

unread,
Feb 9, 2015, 5:08:15 PM2/9/15
to rubyonra...@googlegroups.com
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])
  else
    @people = Person.all
  end

  # ... and whatever else you need to do to prepare for the view...
end

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.


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ade15b3b-b4fd-4224-9da1-6d0ee44bd0eb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jason O

unread,
Feb 10, 2015, 2:00:07 PM2/10/15
to rubyonra...@googlegroups.com
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!
Reply all
Reply to author
Forward
0 new messages