Making REST /bugs/by_state/open URL possible

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.

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.