# Making REST /bugs/by\_state/open URL possible

**URL:** <https://www.ruby-forum.com/t/making-rest-bugs-by-state-open-url-possible/125132>\
**Category:** Rails\
**Created:** [January 5, 2008, 11:41pm UTC](https://www.ruby-forum.com/t/making-rest-bugs-by-state-open-url-possible/125132 "2008-01-05T23:41:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![damaris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/2bfe46/32.png) [@damaris](https://www.ruby-forum.com/u/damaris)\
**Post date:** [January 5, 2008, 11:41pm UTC](https://www.ruby-forum.com/t/making-rest-bugs-by-state-open-url-possible/125132/1 "2008-01-05T23:41:26Z")

</div>

Hi you all,

I have a REST app where I want to consult a resource by all its  
different attributes.  
So I may have the following URLs:

- List of bugs: /bugs
- The bug with id 1, and so on: /bugs/1
- List of values of “whatever”, where “whatever” can be any of the bug  
attributes, such as “state”: /bugs/by\_whatever
- List of bugs whose attribute “whatever” has the value “value”:  
/bugs/by\_whatever/value

I have the first two ones urls working (easy). What about the others? I  
dunno how to rearrange my routes.rb and what to do with my  
BugsController.

- I cannot use nesting resources (nested should have the id of a bug,  
like /bugs/{id}/).
- I’ve started adding a new method called “by\_state” in my  
BugsController, being “state” one of the bug attributes, but an error  
appears when accessing url /bugs/by\_state: “Couldn’t find Bug with  
ID=by\_state”. Obvious.
- Perhaps a new controller could do the trick. Something like  
BugsByController,which would create the /bugs\_by/{whatever} URL.  
But again, I dunno what to do with the {value} part.
- To solve this I can do one controller for each attribute  
BugsByStateController, BugsByâ€¦, but this sounds horrible.
- What about collections? I can have  
map.resources :bugs, :collection =\> { :by\_state=\> :get, by\_dir=\> :get,  
by\_etc… }  
Getting URLs such as /bugs/by\_state, /bugs/by\_dir, etcâ€¦ But again, what  
happens with the “value” part?

Thank you all.

---

<div class="post-metadata">

**Author:** ![damaris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/2bfe46/32.png) [@damaris](https://www.ruby-forum.com/u/damaris)\
**Post date:** [January 6, 2008, 12:12am UTC](https://www.ruby-forum.com/t/making-rest-bugs-by-state-open-url-possible/125132/2 "2008-01-06T00:12:10Z")

</div>

In another thought, I could do something like

map.connect “bugs\_by/:att/:value”,  
:controller =\> “bugs\_by” #my new controller  
:action =\> “filter”  
…

This could do the trick.
