As far as I can see there is an extra ',' (comma) at the end of the first
statement, the statement just before your validates_numericality_of. I have
indicated that below within *[]*. Removing that should solve your issue.

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'

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

Thanks & Regards,
Dhruva Sagar.




On Fri, Dec 4, 2009 at 1:28 PM, pauld <[email protected]> wrote:

> Hi--
>
> I'm having trouble with a syntax error, which I'm working with on page
> 89 of Agile Web Development. I'm getting the following syntax error:
>
> /Users/pdenlinger/Sites/depot/app/models/product.rb:4: syntax error,
> unexpected tSYMBEG, expecting kDO or '{' or '('
>  validates_numericality_of :price
>                             ^
> /Users/pdenlinger/Sites/depot/app/models/product.rb:9: syntax error,
> unexpected tASSOC, expecting kEND
> ...                   :message => 'must be a URL for GIF, JPG' ...
>                              ^
>
> The original code I have on the model (product.rb) is:
>
> 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'
>
> 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
>
>
> Thanks for your help.
>
> Paul
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<rubyonrails-talk%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
>

--

You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.


Reply via email to