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.
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:
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.
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!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.