small medium large xlarge

17 Jan 2008, 22:42
Eric Kinsella (2 posts)

If your following along with the book and doing the examples, on Windows, choose Instant Rails 1.7. If you choose 2.0 you’ll run into a few snags but debugging and researching a new language can be fun too, right?

Our book club is just hitting Chapter 4 at this point. So far so good.

29 Jan 2008, 14:02
Randy Gordon (3 posts)

Not for Newbies. Especially ones that have shelled out money for a book whose target audience are newbies.

Here is the proper code for rails 2.02 for page 23 of Chapter 1 (I will add more replies as I go through the book.)

First of all, when you generate an application, if now defaults to sqllite. If you want mysql, you have to use the command:

rails {application_name} -d mysql

and then, when you want to generate a scaffold (a complete MVC set of files) you need to generate the model with it.

ruby script\generate scaffold {mode_name} {database_column_name}:{database_column_type}

For example, from Rails for Java Programmers, you can generate the People app in one line

ruby script\generate scaffold Person first_name:string last_name:string

Then you need to create the database (explained in the book) and then migrate the database schema into the latest version of the model (if you have a password on MySQL’s root, be sure to add it to config\database.yml)

rake db:migrate

and then just run

ruby script\server

to get a complete, if simplistic database backed web app.

29 Jan 2008, 16:21
Randy Gordon (3 posts)

Another thing. If you are a Java programmer, you are probably used to working in an Eclipse environment. There are a number of (really bad) Eclipse based IDE’s out there. I would suggest using Eclipse For Rails. It puts all these commands as external tools, which means you can modify them for Rails 2 as needed. Other than that, it is easy to follow the book (just try to do that with, say, Aptana’s RadRails plugin.)

You can download Eclipse for Rails at

Personally, I don’t even bother anymore. Unlike with Java, the IDE’s are not powerful enough to be of real help. (I plan on writing an Eclipse plugin for Rails if I ever get time) I develop under Windows, and I keep the following Windows apps open

A command shell in the root directory of the Rails application (for executing rails commands)

MySQL Administrator (in case I need to modify or check the database)

PsPad editor (for editing files) You can download PSPad from It is an editor/notepad replacement that is fast and feature complete. Download the cab version, My Avast! virus scanner said the zip and installer versions had a virus.

A browser open to (in case I need to look up anything). Since I have a subscription to Safari ( I use, it allows me access to a large number of good Ruby and Rails books open in my browser(The Rails Way is a great reference and The Ruby Pocket Reference is very handy

29 Jan 2008, 16:23
Randy Gordon (3 posts)

On page 26, there is a Ruby class definition. This make look a little weird to most Java programmers, but it is mostly a matter of notation

Lets go through it line by line.

class Person < ActiveRecord::Base validates_presence_of :first_name, :last_name end

Ruby classes are similar to Java classes. the ‘<” is the equivalent of Java’s extends keyword; it says that Person subclasses the ActiveRecord::Base class. Unlike Java, a Ruby subclass inherits every method of it’s superclass (including initializers, the equivalent of Java constructors, YAY! That is probably the single biggest problem with Java programming. On the other hand, instance variables are NOT inherited, which takes a bit of getting used to, but makes a lot of sense when you think about it. ).

So what the heck is ActiveRecord::Base? Well, ActiveRecord is a module, and here it is acting as a namespace; grouping various ActiveRecord related classes together. (Module can also be used for multiple inheritance. All classes contained in a module can be included in another class) In this case, the Base class is defined in the \lib\active_record\base.rb file of the ActiveRecord module defined in the Rails gem.

validates_presence_of :first_name, :last_name is actually validates_presence_of( :first_name, :last_name), an overridden method of ActiveRecord::Base. Ruby currently allows programmers to leave off parenthesis, so most programmers do. However, for multiple parameters method calls like this one, the next major version of Ruby will require parenthesis. The colon in front of the parameter names indicates that these are symbols, not strings. Symbols differ from strings in that they are not meant to be manipulated.

Finally end is a key word used to end a block. In Java, blocks are delineated by {} pairs.

05 Feb 2008, 22:16
Eric Kinsella (2 posts)

Thanks for the 2.0 posts. Cheers!

15 Apr 2010, 17:50
Amber (1 post)

Thank you all for the posts on Rails and 2.0 posts. Most of our developers are seasoned Java developers and now we are learning RR - our company (a online marketplace) thinks that software development using Java is too slow and costly and wants to give Rails a try.

The posts here certainly helps and we’ll see if the code also works on the coming 3.0 release, which is the version we’ll use.