I am learning ruby on rails. So, I created a sample application in which I am displaying some stuffs. Now I want to add the functionality of narrowing down items depending upon user’s selection like changing price ranges, selecting type and so on.
Please suggest some articles / tutorials which can help.
Do this through model finders.
e.g.
http://railscasts.com/episodes/37-simple-search-form
http://railscasts.com/episodes/111-advanced-search-form
This tutorial is about scopes… http://railscasts.com/episodes/111-advanced-search-form but is very relevant and actually has some of the simplest examples.
One of the biggest gains from doing the search in the model (as opposed to the controller) is testing. You can now have unit tests, e.g. rspec model tests if you use rspec, just within the model.
Perhaps you want dynamic scope?
Dynamic scopes allow filtering on the fly and method chaining. For example: