Restful rails: when simple just isn't enough

[snip]

Okay, first up is a disclaimer. I'm still getting my feet wet with REST so this might be totally wrong. Proceed at your own risk.

When looking at your collection from these other perspectives (recent = time, status = enabled/disabled/featured/etc), these other perspectives become controllers.

GET example.com/recent This returns some default timespan of recent articles.

GET example.com/recent/45 This returns articles from the past 45 days.

Or maybe you just take additional parameters in to your regular #show method. GET example.com/articles?begin=today&end=45 This might behave just like the #recent/45 example above.

I highly recommend looking at the articles on wikipedia [1] and RestWiki [2] to understand how to apply REST principles. The REST approach will likely result in more controllers, but each controller will be much simpler to implement and test. If you are still stuck in the mode that says there is a 1:1 relationship between controllers and models then you might be in for a rough ride.

cr

[1] Representational state transfer - Wikipedia [2] http://rest.blueoxen.net/cgi-bin/wiki.pl?FrontPage

Steve Dogers wrote:

Thank you!

Can anyone confirm Chuck's highlights? I get this feeling RESTful application are still very much bleeding edge...

Like Chuck, I'm no REST expert, but am halfway through refactoring an app to be RESTful, and it's improving it no end. The structure is stronger, the reasoning better, and the whole thing is a lot less messy.

In all my RESTful controllers I'm set up the :index action to display the 20 most recent items, and if I need to filter it, perhaps by restricting them to items that are tagged with "foo", I simply pass a :tag => "foo" parameter along with the request. It's trivial if there's just one possible filter, not that much more difficult using case..when with using more than one possible one. I've only needed to resort to additional actions in a couple of controllers (and it's a fairly big app), and in those it's been for specific destructive actions, e.g. disapproving an item.

HTH CT