Refactoring code logically
And now an example of how I write my ruby code and get it down to the bare, readable, minimum code needed. This is real life code taken from a website I'm building, but I've changed the objects to a blog post because more people will relate to that easier.
The show object has an id passed in using the params Hash, I want to check if that post exists in the database first. If it does, then render the page, and if it doesn't return a 404 error page.
So I start off by writing this in longhand ruby, I'm using the merb framework with DataMapper ORM by the way....
More...