small medium large xlarge

Generic-user-small
23 Feb 2012, 22:32
Mat Doidge (3 posts)

Hi there,

I’ve just started the ebook and already ive hit problems. Upon changing the migrate file to:

class CreateProducts < ActiveRecord::Migration def change create_table :products do |t| t.string :title t.text :description t.string :image_url t.decimal :price, precision: 8, scale: 2 t.timestamps end end end

I’m getting the error:

C:\Users\Mat\work\depot>rake db:migrate rake aborted! C:/Users/Mat/work/depot/db/migrate/20120223214304_create_products.rb:7: syntax e rror, unexpected tINTEGER, expecting kEND t.decimal :price, :precision 8, scale: 2 ^

Tasks: TOP => db:migrate (See full trace by running task with –trace)

I’ve checked and it’s identical to the books format and there’s no rogue characters. Can anyone help me?

Regards M

Generic-user-small
23 Feb 2012, 23:28
Mat Doidge (3 posts)

It would seem i found out how to get it working by writing:

` class CreateProducts < ActiveRecord::Migration def change create_table :products do |t| t.string :title t.text :description t.string :image_url t.decimal :price, :precision => 8, :scale => 2

  t.timestamps
end   end end

`

It would seem i needed to add ‘:’ before precision and ‘=>’ after. Does this mean im using a more recent version of rails than the book or an old version.. as far as i can see i should be on the same as the book.. im confused now.

M

Foto criada em 2010-06-17 às 00.19_pragsmall
24 Feb 2012, 01:31
Daniel Freire (3 posts)

Which is your ruby version?

Dave_gnome_head_isolated_pragsmall
24 Feb 2012, 20:46
Dave Thomas (390 posts)

The syntax

precision: 8, scale: 2

was introduced in Ruby 1.9 (which is the Ruby used in the book). The older

:precision => 8, :scale => 2

works in both.

You must be logged in to comment