0

I want to be able to sort easily through the User model. So in the view, you might see a few options to sort. A choice of two radio buttons, one for popular and one for latest. To find the popular users (based on their followers count):

/people?sort=popular

Or you could select the other radio to just find the most recent users:

/people?sort=latest

Then from their you can select a checkbox (where you can select multiple) like most posts to find the users with the most posts and that are the most popular:

/people?sort=popular&posts=on

And another checkbox to find the user's that are contactable (which is a boolean value stored in the user's table)

 /people?sort=popular&posts=on&contactable=on

I hope this makes sense. Dribbble does this very well when you sort through their Designers. Can anyone point me in the right direction to accomplish this?? Thanks. Once I have a general understand on how to accomplish this I can add more options to sort as well. Also, I don't need AJAX so a page refresh each query is perfectly OK.

1 Answer 1

1

In Rails, every controller action has access to a params hash. A params hash has many things including a key/value structure for each item in the query string.

So in your people#index action, you will have the following available:

params[:sort] #=> value is "popular"
params[:posts] #=> value is  "on"
params[:contactable] #=> value is "on"

You can pass those as where clauses to your User model.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.