Monday, April 28, 2008

RESTing

Ok so I used scaffold and done a few tutorials before launching into my own project. I knew REST and CRUD and all that stuff were important but never really understood them. Im not saying I completely understand the concepts yet, but I am starting to realise their importance, especially after my project was getting messier and messier and when I started to think along these lines ... "This is rails, why the hell do I need to hack this controller to get it to do something simple" I turned to google to see what I was missing.

First blog I came across was this one http://www.rubyrailways.com/great-ruby-on-rails-rest-resources/ which lead me to a series of blogs from softiesonrails which made things alot clearer.

Part 1 - http://www.softiesonrails.com/2007/3/28/rest-101-part-1-understanding-resources

Part 2 - http://www.softiesonrails.com/2007/4/3/rest-101-part-2-a-million-apis

Part 3 - http://www.softiesonrails.com/2007/4/10/rest-101-part-3-just-call-me-the-repo-man

Part 4 - http://www.softiesonrails.com/2007/4/18/rest-101-part-4-routing

Part 5 - http://softiesonrails.com/2007/5/1/rest-101-part-5-respond

One of the main things I got out of these blogs was this paragraph from Part 4

You may already be wondering how in the world you're going to develop a Rails application if those are the only actions you're allowed to have in your controllers. Well, first of all, don't worry. If you really, really think you have a situation that requires a few extra actions, then go right ahead and add them to your controller. Just remember that having any extra actions can be a warning sign that you haven't identified all of your resources yet.


After trying to hack on extra actions to my controllers i finally realised that I was treating rails with contempt. It was trying to push me to use the REST and CRUD principals while I was trying make it work without really understanding what i was doing. I still wasn't thinking of my app in terms of resources.

The series mentioned above is invaluable for rails newbies like me that have a bit of an understanding but are still trying to use almost OO concepts to build websites.

No comments: