Saturday, April 2, 2011

A script for a Ruby on Rails Blog in 15 minutes

Early in the new year I made the switch to Vim from Textmate. I needed a lot of practice so I replicated the Rails screen-cast for a blog in 15 minutes produced by Ryan Bates over and over again. It was a great way to get familiar with Vim after years of Textmate editing. I wrote up a script based on that screen-cast to aid my practice, and I have also found it useful in quickly demoing Rails to a newbie. The script itself won’t make sense without viewing the screen-cast, but a good reminder of the steps if you find yourself in the same situation.

  • Create a new rails application
  • Start and verify server is running
  • Generate Post (title, body) scaffold
  • Demonstrate adding, updating Posts
  • Add validation rule to Post
  • Demonstrate adding an invalid post
  • Refactor posts/show view into partial
  • Refactor posts/index to use partial
  • Demonstrate in browser
  • Demonstrate XML (curl http://localhost:3000/posts.xml)
  • Add JSON format for Posts
  • Demonstrate JSON (curl http://localhost:3000/posts.json)
  • Add atom format (posts/index.atom.builder)
  • Add auto_discover_link_tag to layout
  • Add basic authentication to PostsController
  • Demonstrate in browser
  • Add Comment scaffold (body)
  • Don’t forget to update routes
  • Demonstrate routes (rake route)
  • Add list of comments to posts/show
  • Create comments partial
  • Add comments form to posts/show
  • Clear out CommentsController
  • Add create action (but use #build instead of #create!)
  • Create does not save, show off debugger
  • Demonstrating save comment in debugger
  • Change build method to #create!
  • Update comments form to use AJAX
  • Update comments controller to use AJAX
  • Demonstrate fall back without Javascript enabled
  • Create automated test for posting comments
  • Review with broken test
  • Review console by updating a post title, add comment

Here are the various 15 minute blog screen-casts for the different versions of Rails:

Please note this blog is no longer maintained. Please visit CivilCode Inc - Custom Software Development.