What's New in Edge Rails: Restful Routes

Posted by Jeremy Voorhis Mon, 31 Jul 2006 03:03:00 GMT

While I’m no Ryan Daigle1, I do subscribe to the Rails trac RSS feed and decided to speak up after watching this changeset roll in.

simply_restful began its life as a plugin, and at RailsConf, the core team announced that it would be merged into Rails core.

simply_restful has been merged into Rails core. Its functionality seems basically intact, with one minor adjustment: resource names are now pluralized. This means that in your routes.rb file, you must specify


  map.resource :entries

instead of


  map.resource :entry

The same goes for the companion method resources, which allows you to declare multiple resources at once.

In addition to providing clean URLs which respond to multiple HTTP methods, simply_restful also allows you to specify additional actions which respond to certain verbs like so:


  map.resources :comments, :member => { :approve => :post }

In this case, the url /comments/1;approve would be created. The rationale is to use the path to the left of the semicolon for a resource’s identity, and to use the path to the right of the semicolon as a modifier. Frequently this modifier would be an operation that you would perform on the resource, such as approving a comment that requires moderation.

In the plugin version of simply_restful, there was a bug which allowed only one additional action per HTTP method – you could not have two semicolon-style URLs which accepted the GET method, for example. This bug has been fixed.

I have yet to verify whether the pluralization issue affects this incarnation of simply_restful, but this would be a good time to release a plugin of my own that scratches an itch of mine since the plugin was released.

1 While the Rails changeset log is certainly available for everyone to read, Ryan provides a good service for anyone who wants a periodical synopsis of the latest changes, rather than a constant trickle. Thanks, Ryan!

Comments

  1. rick said about 1 hour later:

    <pre><code> map.resources :whatevers, :singular => :whatever </code></pre>

    There is an issue because you need some way distinguish collection routes from member routes. The above should work for that.

  2. Ryan Daigle said about 4 hours later:

    Ok Jeremy, now why you got to be go stealing my thunder like that… :) j/k – there’s plenty of updates to go around. Love your blog – keep up the good work.

  3. kogent said about 17 hours later:

    Is there a way to get this to work without a semicolon? the semicolon makes it seem less pretty.

  4. JV said about 18 hours later:

    You can always add an additional route in addition to the restful routes declaration that doesn’t use the semi-colon.

  5. DHH said 1 day later:

    The semicolon is also there to deter you from using it. Lots of times you can refactor to be more restful and not need additional actions if you just think harder. The semicolon is an invitation to think more.

  6. gambling? said 9 days later:

    This online bingo is whimsically varied. Some greek arm threw underneath a necessary example. This history is wholeheartedly sensitive. Dear me, one interest is far more bare than a free online bingo. Family outdid the bingo online.

(leave url/email »)