Generic-user-small Bruce C. Mar... 5 posts

I have just started working with AWDR and have the beta of the third edition. I have run into a problem when trying to validate the image url. Here is what I have in the product.rb file, excluding the begining and ending quotes.

“class Product < ActiveRecord::Base validates_presence_of :title, :description, :image_url validates_numericality_of :price validate :price_must_be_at_least_a_cent validates_uniqueness_of :title validates_format_of :image_url :with => %r{.(gif|jpg|png)$}i, :message => “must be a URL for GIF, JPG or PNG image.(gif/jpg/png)”

protected def price_must_be_at_least_a_cent errors.add(:price, ‘should be at least 0.01’)if price.nil? || price < 0.01 end
end”

but I end up with the follow error when I refresh the page.

C:/Ruby_Test/depot/app/models/product.rb:7: syntax error, unexpected tASSOC, expecting kEND :with => %r{.(gif|jpg|png)$}i, ^
C:/Ruby_Test/depot/app/models/product.rb:7: syntax error, unexpected ’,’, expecting kEND

did I miss something in the book?

Bruce

 
Samr_small_small Sam Ruby 109 posts

There needs to be a comma (”,”) at the end of the line that reads “validates_format_of :image_url,”. Without that comma, Ruby thinks that the statement is complete, and gets confused when it attempts to process the next line.

 
Generic-user-small Bruce C. Mar... 5 posts

That’s it for some reason my mind looked right over the comma. It’s in the text plain as day. Thanks.

Bruce

3 posts, 2 voices