RSS Feed  August 28th, 2008

Essential Rails Class Notes

Added: September 24th, 2007 (tagged with: coding, conference)

Last Friday and Saturday (9/21 and 9/22) I attended the Essential Rails hands-on, interactive workshop for people new to Ruby and the Rails framework. The goals of the class were to teach the following:

  • Ruby essentials and syntax (and made especially easy for those from a C# or VB background)
  • The Rails "stack" and the HTTP pipeline
  • Open source tools and applications (Subversion, MySQL, SSH, and more)
  • Rails conventions and (gasp!) configuration
  • REST and what it means in Rails
  • ActiveRecord and migrations
  • ActionPack: ERb, forms, templates, partials, layouts, and helpers
  • Test-driven development with Rails
  • AJAX with Rails
  • Hosting and deployment basics
  • Real-life lessons learned

-- From the "What will I actually learn?" section of the Essential Rails web site.

I've been developing in Ruby on Rails for a couple of months now, so I am fimilar with the basics, but it was nice to have a refresher course. The Essential Rails training course re-enforced the concepts and ideas I have learned thus far and added to my knowledge of the framework (especially in REST and Rake).

Essential Rails - Day 1 Notes

Ruby is an Object-Oriented Dynamically-Typed Scripting Language created by Yukihiro Matsumoto (Matz) and influenced by C, Smalltalk, Lisp

Object.methods returns list of methods available for the given object.

When creating migrations, you can create database indexes by using add_index :table_name, :column_name

Filters are used to remove common code that runs at a particular time. Example: before_filter :find, :only => [:show, :edit] runs the find method before the show and edit actions only.

Essential Rails - Day 2 Notes

Three Step Process for RESTful Apps

  1. Identify Your Resources
  2. Use map.resources (then implement the Seven Actions)
  3. There is no step three

Using map.resources :class_name in your config/routes.db file, Rails automatically generates four helper methods:

The Seven Actions
URL PathRESTful ActionRails Controller Action
/productsGETindex
/productsPOSTcreate
/products/1PUTupdate
/products/1DELETEdestroy
/products/1GETshow
/products/newGETnew
/products/1;editGETedit

To create your own rake tasks, you will first need to create a file named 'rakefile' (with no extension). Then, you can create as may task blocks inside rakefile as you like (you need to add the desc if you want your task to appear in the task list using rake -T or rake --tasks:

desc "This is a short description of the task that follows"
task :tast_name => [:dependent_task, ...] do
  ruby stuff
end

To add tasks to your rails app, add a *.rake file in the lib/tasks directory. The is a special :environment task that you can depend on if your task requires a rails environment to be setup before it runs. You can also create a namespace block to ensure you don't overwrite any predefined rake tasks:

namespace :your_namespace_name do

  desc "This is a short description of the task that follows"
  task :tast_name => [:dependent_task, ...] do
    ruby stuff
  end

end

Shared Hosting Environments - About $5-$20 per month

VPS Environments - About $50+ per month

© 2006 - 2008 Michael J. Sepcot - michael (dot) sepcot (at) gmail (dot) com