Ruby Tutorials Notes, Links and other Goodies (tutorials.shtml) | Updated: 23-Sep-2008 - 14:54
The following should already be installed is running OS X 10.5 Leopard:
In Leopard and Leopard Server, Ruby and Rails are pre-installed along with a bounty of other useful RubyGems. This means we can hit the ground running when it comes to developing a Rails application and keep up the pace when deploying new releases of our application to Leopard Server.
Out of the box, you get Ruby version 1.8.6 and Rails version 1.2.6, the latest stable releases at the time Leopard shipped. Ruby releases are few and far between (it's still at 1.8.6), but Rails has frequent new releases. In fact, the application we'll build requires Rails 2.0.2. The good news is it's easy to upgrade Rails and RubyGems. Make sure your system is up to date now by running these commands:
The first command updates the RubyGems system itself, which is required by the latest version of Rails. The second command updates Rails-specific gems and installs any new components (specifically Active Resource). The third command updates Rake, the make-like build tool used by Rails. Finally, the last command updates the Ruby bindings for the SQLite3 database. Running all these commands may take a while. When it's finished, you can list all the installed gems by typing
$ gem list$rails todo$cd todo$rake db:create:all$script/generate scaffold Todo title:string body:text done:boolean due:datetime$rake db:migrateThen start the web server
$script/serverOpen your browser to http://localhost:3000/todos
While working through a book on Ruby on Rails 1.2 you will have trouble getting something up and running as there have been changes in Rails 2.0. I did. So with the wonders of the web and fellow Ruby explorers that come before us one can track down what is need to get things going.
This is a multi-part tutorial covering enough to get a scaffolded Rails application up and running under Rails 2.0.
Based on Sean Lynch's tutorial at: fairleads: Rails 2.0 and Scaffolding Step by Step tutorial
The following should already be installed is running OS X 10.5 Leopard:
In Leopard and Leopard Server, Ruby and Rails are pre-installed along with a bounty of other useful RubyGems. This means we can hit the ground running when it comes to developing a Rails application and keep up the pace when deploying new releases of our application to Leopard Server.
Out of the box, you get Ruby version 1.8.6 and Rails version 1.2.6, the latest stable releases at the time Leopard shipped. Ruby releases are few and far between (it's still at 1.8.6), but Rails has frequent new releases. In fact, the application we'll build requires Rails 2.0.2. The good news is it's easy to upgrade Rails and RubyGems. Make sure your system is up to date now by running these commands:
The first command updates the RubyGems system itself, which is required by the latest version of Rails. The second command updates Rails-specific gems and installs any new components (specifically Active Resource). The third command updates Rake, the make-like build tool used by Rails. Finally, the last command updates the Ruby bindings for the SQLite3 database. Running all these commands may take a while. When it's finished, you can list all the installed gems by typing
$ gem list$ rails exchangeNext, open the new project directory with TextMate
by typing mate exchange or dragging the new project folder to the TextMate icon in the Finder or the Dock.
$ mate exchange
$ cd exchange$ script/server exchangeNow point your web browser at http://localhost:3000

The following database servers are currently supported by Rails: MySQL, PostgreSQL, SQLite (SQLite3 is the default), SQL Server, DB2, Firebird, and Oracle.

$ rake db:create:alldb:create:all Create all the local databases defined in config/database.yml (above )

$ script/generate scaffold Movie title:string description:text one_sheet_url:string
Rails 2.0 is REST (Representational State Transfer) by default. The usual suspects are created: Controller, Helper, Model, Migration, Unit Test, Functional Test
The scaffold command contains the database "Movie" and the columns that added. The columns can also be added by hand.

$ rake db:migrate
Curt:exchange curt$ rake db:migrate
(in /Users/curt/dev/exchange)
== 1 CreateMovies: migrating ==================================================
-- create_table(:movies)
-> 0.0021s
== 1 CreateMovies: migrated (0.0022s) =========================================
Now point your web browser at http://localhost:3000/movies


At this point you can follow part 1 of Sean Lynch's the tutorial at
This was the first time I could get Rails 2.0 running on om my Mac. The only problem I had with the tutorial was in part 2 and the validates_format_of code. I was getting an error I can't figure out in the :with
The following should already be installed is running OS X 10.5 Leopard:
In Leopard and Leopard Server, Ruby and Rails are pre-installed along with a bounty of other useful RubyGems. This means we can hit the ground running when it comes to developing a Rails application and keep up the pace when deploying new releases of our application to Leopard Server.
Out of the box, you get Ruby version 1.8.6 and Rails version 1.2.6, the latest stable releases at the time Leopard shipped. Ruby releases are few and far between (it's still at 1.8.6), but Rails has frequent new releases. In fact, the application we'll build requires Rails 2.0.2. The good news is it's easy to upgrade Rails and RubyGems. Make sure your system is up to date now by running these commands:
The first command updates the RubyGems system itself, which is required by the latest version of Rails. The second command updates Rails-specific gems and installs any new components (specifically Active Resource). The third command updates Rake, the make-like build tool used by Rails. Finally, the last command updates the Ruby bindings for the SQLite3 database. Running all these commands may take a while. When it's finished, you can list all the installed gems by typing
$ gem listBased on the Apple Developer's tutorial Developing Rails Applications on Mac OS X Leopard
$ rails expenses
Add a s shell script for script/server as a Top Level Organizer Item to the expenses folder.
Or, using the Terminal application start the server $ script/server
Now point Safari at http://localhost:3000. You should see a web page welcoming you aboard Rails.
The following database servers are currently supported by Rails: MySQL, PostgreSQL, SQLite (SQLite3 is the default), SQL Server, DB2, Firebird, and Oracle.

$ rake db:create:alldb:create:all Create all the local databases defined in config/database.yml (above )

$ cd expenses
$ script/generate scaffold event name:string budget:decimal
Rails 2.0 is REST (Representational State Transfer) by default. The usual suspects are created: Controller, Helper, Model, Migration, Unit Test, Functional Test
The scaffold command contains the database "event" and the columns that added. The columns can also be added by hand.
$ rake db:migrateRails applications use Rake (Ruby's equivalent of Make) to automate recurring tasks such as applying migrations. We could run rake db:migrate from a Terminal command line, but again the Organizer makes this easier. All the Rake tasks are already available as pre-configured actions.

Now point your web browser at http://localhost:3000/events
$ script/generate scaffold vendor name:string email:string
$ db:migrate
$ script/generate resource expense event_id:integer vendor_id:integer amount:decimal
$ db:migrate
Declare the associations in the models as follows:
class Expense < ActiveRecord::Base belongs_to :event belongs_to :vendor end
class Event < ActiveRecord::Base validates_presence_of :name validates_numericality_of :budget, :greater_than => 0.0 has_many :expenses has_many :vendors, :through => :expenses end
class Vendor < ActiveRecord::Base has_many :expenses has_many :events, :through => :expenses end