Forum: Ruby on Rails parsing arrays from globbed routes into controller

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
7e4e4ee43e45c1ab62f3bb21d6f4f566?d=identicon&s=25 johnsonmlw (Guest)
on 2009-03-15 23:34
(Received via mailing list)
I have this in routes.rb:

map.connect 'pupils/*filters', :controller => "pupils", :action =>

Given this url, for example:


I would like to be able to grab an unlimited number of values to
filter pupils in the controller (so I don't have to write out all the
options in route.rb)

So far I have... (but clearly this isn't going to work)

def filter
@pupils = Pupil.find(:all, :conditions => params[:filters])

I found this with google but it complains about an odd number of

@pupils = Pupil.find(:all, :conditions => Hash[params[:filters]])

Please help me with the controller find line, or tell me this isn't
the way to be doing this at all.


872535e214a9e3a98889bd8d069f0294?d=identicon&s=25 "Wolas!" (Guest)
on 2009-03-16 11:10
(Received via mailing list)
I dont think this is the way to do this at all.

I have been told it is not wise to have very nested resources (2
maximun) so with a better design, you might come up with something
where you can do filtering in routes

map.resources :pupils, :has_many => {:houses, :cohorts, ...}, :has_one
=> {:mansion, ...}

this will give you routes like

pupils/2/cohorts/:cohort_id => will go to controller cohorts, action
show and params will contain :pupil_id => 2
pupils/2/cohorts => will go to controller cohorts, action index and
params will contain :pupil_id => 2
pupils/2/houses/:cohort_id => will go to controller houses, action
show and params will contain :pupil_id => 2

... etc

so you dont have to write ALL the possible routes, but you have to
route all the parameters you want to filter by. This is a solution to
what it seems your problem here, but i suggest you have a good think
in your design as to why you would need to filter pupils in the routes
and not in the index page of the pupils controller (for example) or
somewhere where it is more "appropiate" (easier).
This topic is locked and can not be replied to.