pauld
2009-Dec-04 07:58 UTC
Need help debugging syntax error from Agile Web Development, 3RD Edition
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Christoph Jasinski
2009-Dec-04 08:02 UTC
Re: Need help debugging syntax error from Agile Web Development, 3RD Edition
That''s an easy one, really. You got a typo. ****************************************** class Product < ActiveRecord::Base validates_presence_of :title, :description, :image_url, validates_numericality_of :price ****************************************** remove the last comma from the line above the validation of the numericality of :price Cheers, Chris -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Dhruva Sagar
2009-Dec-04 08:03 UTC
Re: Need help debugging syntax error from Agile Web Development, 3RD Edition
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
<paul.denlinger-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
>
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
> .
> 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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
pauld
2009-Dec-04 08:16 UTC
Re: Need help debugging syntax error from Agile Web Development, 3RD Edition
Thank you.
I''m still getting an error for the second statement:
/Users/pdenlinger/Sites/depot/app/models/product.rb:9: syntax error,
unexpected tASSOC, expecting kEND
... :message => ''must be a URL for GIF,
JPG'' ...
^
The code is as follows:
validates_format_of :image_url,
:with => %r{\.(gif|jpg|png$)}i
:message => ''must be a URL for GIF,
JPG'' + ''or
PNG image''
Thanks,
Paul
On Dec 4, 4:03 pm, Dhruva Sagar
<dhruva.sa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> 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
<paul.denlin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > To unsubscribe from this group, send email to
> >
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib
e@googlegroups.com>
> > .
> > 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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2009-Dec-04 08:23 UTC
Re: Re: Need help debugging syntax error from Agile Web Development, 3RD Edition
2009/12/4 pauld <paul.denlinger-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> Thank you. > > I''m still getting an error for the second statement: > > /Users/pdenlinger/Sites/depot/app/models/product.rb:9: syntax error, > unexpected tASSOC, expecting kEND > ... :message => ''must be a URL for GIF, JPG'' ... > ^ > > The code is as follows: > > validates_format_of :image_url, > :with => %r{\.(gif|jpg|png$)}i > :message => ''must be a URL for GIF, JPG'' + ''or > PNG image''I know it is difficult when just starting, but I would have thought that following the previous problem with a comma that you could have worked out this one yourself. When you see a syntax error the problem saying something unexpected found that means that there is likely an error a bit before the point noted. The basic syntax of validates_format_of (or any function for that matter) is validates_format_of <parameter>, <parameter>, ... :image_url is the first parameter, :with => ... is the second and :message => .. is the third. I am sure you can see the error, or at least the one generating the message. Colin -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Tom Stuart
2009-Dec-04 08:46 UTC
Re: Re: Need help debugging syntax error from Agile Web Development, 3RD Edition
2009/12/4 pauld <paul.denlinger-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> Thank you. > > I''m still getting an error for the second statement: > > /Users/pdenlinger/Sites/depot/app/models/product.rb:9: syntax error, > unexpected tASSOC, expecting kEND > ... :message => ''must be a URL for GIF, JPG'' ... > ^ > > The code is as follows: > > validates_format_of :image_url, > :with => %r{\.(gif|jpg|png$)}i > :message => ''must be a URL for GIF, JPG'' + ''or > PNG image'' > > Thanks, > PaulHi Paul, This is the same error as the previous one, but in reverse. ;) Cheers, Tom -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
pauld
2009-Dec-04 08:48 UTC
Re: Need help debugging syntax error from Agile Web Development, 3RD Edition
Hi Colin-- Thanks. Got the errors. Two missing commas. Will try to avoid repeating that mistake in the future. Paul On Dec 4, 4:23 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2009/12/4 pauld <paul.denlin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > Thank you. > > > I''m still getting an error for the second statement: > > > /Users/pdenlinger/Sites/depot/app/models/product.rb:9: syntax error, > > unexpected tASSOC, expecting kEND > > ... :message => ''must be a URL for GIF, JPG'' ... > > ^ > > > The code is as follows: > > > validates_format_of :image_url, > > :with => %r{\.(gif|jpg|png$)}i > > :message => ''must be a URL for GIF, JPG'' + ''or > > PNG image'' > > I know it is difficult when just starting, but I would have thought > that following the previous problem with a comma that you could have > worked out this one yourself. When you see a syntax error the problem > saying something unexpected found that means that there is likely an > error a bit before the point noted. The basic syntax of > validates_format_of (or any function for that matter) is > validates_format_of <parameter>, <parameter>, ... :image_url is the > first parameter, :with => ... is the second and :message => .. is the > third. I am sure you can see the error, or at least the one > generating the message. > > Colin-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.