The speed of progress is too fast sometimes

I have just started trying to learn Ruby on Rails. I bought a couple of books several months ago but never got around to reading them until the other day, when I started reading Agile Web Development with Rails (Fifth Printing, February 2006, Version: 2006-2-16).

The first problem I encountered was connecting to my MySQL database, which unlike the authors’, is on a different machine from my development machine. I have a media/tv recording server that runs all the time and has MySQL installed on it, so I thought I’d just use that. But the book doesn’t seem to cater for remote connections. It turns out all I had to do was to specify the port in the application_name/config/database.yml configuration file. So I ended up with the following:-

development:
adapter: mysql
encoding: utf8
database: depot_development
username: antony
password: ***********
host: *********
port: 3306

The second problem I came across was that the scaffold generator has changed since the book was written. On page 57 the author asks us the run this from a command prompt:-

depot> ruby script/generate scaffold Product Admin

The problem is that the scaffold generator has been changed to not take the Controller as a parameter, in this case Admin. It now creates the controller as the plural of the model. So what is actually needed is:-

depot> ruby script/generate scaffold Product

But, this still has a problem in that it doesn’t know what fields are in the database table. So a further refinement is needed.

depot> ruby script/generate scaffold Product id:int title:varchar description:text image_url:varchar price:decimal -f

The -f just forces the generator to overwrite any pre-existing files. This worked just fine and I have tested the application by adding a record and checking it ended up in my (remote) database. I’ve also destroyed a record too, and that worked just fine. It even had a confirmation dialog, asking me if I was sure, a nice touch.

There is an errata web page for this book, which can be found here.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s