# Parsing arrays from globbed routes into controller

**URL:** <https://www.ruby-forum.com/t/parsing-arrays-from-globbed-routes-into-controller/162938>\
**Category:** Rails\
**Created:** [March 15, 2009, 11:34pm UTC](https://www.ruby-forum.com/t/parsing-arrays-from-globbed-routes-into-controller/162938 "2009-03-15T23:34:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnsonmlw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f05b48/32.png) [@johnsonmlw](https://www.ruby-forum.com/u/johnsonmlw)\
**Post date:** [March 15, 2009, 11:34pm UTC](https://www.ruby-forum.com/t/parsing-arrays-from-globbed-routes-into-controller/162938/1 "2009-03-15T23:34:57Z")

</div>

I have this in routes.rb:

map.connect ‘pupils/\*filters’, :controller =\> “pupils”, :action =\>  
“:filter”

Given this url, for example:

[http://localhost:3000/pupils/cohort\_id/1/house\_id/3](http://localhost:3000/pupils/cohort_id/1/house_id/3)

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])  
end

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

@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.

Thanks.

–  
Matt

---

<div class="post-metadata">

**Author:** ![johnsonmlw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f05b48/32.png) [@johnsonmlw](https://www.ruby-forum.com/u/johnsonmlw)\
**Post date:** [March 16, 2009, 11:10am UTC](https://www.ruby-forum.com/t/parsing-arrays-from-globbed-routes-into-controller/162938/2 "2009-03-16T11:10:42Z")

</div>

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).
