Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: RESTful resources: Worth using or inflexible/overrated?

I've been messing about in rails the past 2 months and so far everything's going well - but there's one area I'm a little doubtful on.

I keep hearing about the joys of RESTful rails resources: that is, a 'resource :foo' in config/routes, and your 7 restful actions in the controller.

Except for very simple things (eg stuff that's 99% done by running 'generate scaffold'), I find it's less convenient to try squeeze my project functionality into that approach than to just match urls in config/routes one-by-one and do each action as needed.

But I keep getting the sense that I'm wrong, and that in all but the most extreme circumstances, RESTful resources are the way to go.

So:

(a) Can anyone offer an opinion on this?

(b) For experienced rails folks, what % of your routes in a typical project are :resources and what % are coded action-by-action? Cheers...

like image 457
PlankTon Avatar asked Nov 22 '10 19:11

PlankTon


1 Answers

Resources are convenient, but they are not a "one size fits all" feature. Some things just don't make sense with the 7 methods.

Keep in mind that you can:

  • Exclude specific methods with :except.
  • Include only specific methods with :only.
  • Add your own methods to the resource.

So they aren't as inflexible as you may think. But if, after taking those 3 points in mind, the resource just doesn't "feel right", skip it! REST was never meant to replace regular routing, it just tries to abstract away the most common use case.

If you skip out on RESTful resources completely, you'll be missing a ton of free functionality. Use it wisely and you'll be fine.

like image 89
ryeguy Avatar answered Sep 23 '22 04:09

ryeguy