Sunday, December 3rd, 2006

Working through Agile Web Development with Rails – Part 1



Working through the book I have listed some of the ‘Gotchas’ that I encountered and solutions to these.

  • Playtime – Page 59

    The example in the book shows the line @files = Dir.glob(’*')

    This should read @files = Dir.glob(”*”) - note the double quote (the online example does use this)

  • Iteration A2 – Add a missing column – Page 81

    This will give you an error similar to this

    =>rake db:migrate

    (in C:/Documents and Settings/Andrew/My Documents/RadRails_Workspace/depot)

    == AddPrice: migrating ========================================================

    – add_column(:products, :price, :decimal, {:precision=>8, :scale=>2, :default=>0})

    rake aborted!

    You have a nil object when you didn’t expect it!

    You might have expected an instance of Array.

    The error occured while evaluating nil.[]

    (See full trace by running task with –trace)

    This is because you need to be running Rails V1.2, this is explained when you work through the introduction but easy to forget to update when you start the depot application. This is because V1.1 does not support decimals!

    To resolve:-

  1. Copy the Rails 1.2 (pre-release) files to the <your projects>\depot\vendor directory
  2. Run the command

    rake rails:update

  3. This updates rails, you can now run the command

    rake db:migrate

    This should sown something like the information below, the column now being added.

=>rake rails:update

(in C:/Documents and Settings/Andrew/My Documents/RadRails_Workspace/depot)

install -c -m 0755 C:/Documents and Settings/Andrew/My Documents/RadRails_Workspace/depot/config/../vendor/rails/railties/lib/tasks/../../bin/process/inspector script/process/inspector

=>rake db:migrate

(in C:/Documents and Settings/Andrew/My Documents/RadRails_Workspace/depot)

== AddPrice: migrating ========================================================

– add_column(:products, :price, :decimal, {:default=>0, :precision=>8, :scale=>2})
-> 0.6310s

== AddPrice: migrated (0.6310s) ===============================================

  • Upgrade to MySQL 5.0.27

    This was not a Gotcha but I did this whilst trying to solve the decimal issue above. One thing it does show is how well the migration approach works.

    • Downloaded and installed the latest version of MySQL
    • Stopped MySQL in instant Rails (this is version 4.1.9-max)
    • Started Instant Rails (via Service in Windows)
    • Run the commands

    mysqladmin –u root create depot_development

    rake db:migrate

    • You will lose you 1 sample record (real migration I think is covered later in the book J)
  • Iteration 4: Prettier Lisitings – Page 86

    Running the command:

    ruby script/generate scaffold product admin

    generates the static scaffold, however in my setup this resulted in some of the forms not working. The listings page displayed correctly but when choosing New Product I was presented with the header and footer but no form. After some investigation it appears that the form_tag
    was generated incorrectly, I am not sure why this is although we are using the unsupported V1.2 from the pragmatic programmers so expect some issues.

    Replace the code in the file new.rhtml

    <% form_tag :action => ‘create’ do %>

    with

    <% form_for :product do |form| %>

    Replace the code in the file edit.rhtml

    <% form_tag :action => ‘update’, :id => @product do %>

    With

    <% form_for :product, :url => { :action => “update”, :id => @product} do |form| %>

This takes me up to Chapter 7, Please comment on this post if you spot any mistakes or things I could do to improve the code. I will note any revisions I make as my knowledge of Rails develops.


…continued in part 2

blog comments powered by Disqus