Agile Web Dev (book) question: errors

This is kind of frustrating (but no doubt helpful in the long run) that
after following along and coding , and d/l the code the same error is
appearing.
For those who are familiar with the depot app, I’ve run into a problem
after
fixing the cart to reflect quanitites. I worked through the intended
error
messages but now have this appearing:

SyntaxError in StoreController#add_to_cart

app/models/cart.rb:15: parse error, unexpected $, expecting kEND

Not sure where to turn to figure this out being a newb.

TIA
Stuart

Dark A. wrote:

app/models/cart.rb:15: parse error, unexpected $, expecting kEND

Not sure where to turn to figure this out being a newb.

TIA
Stuart

Can you post a few lines before and after Line 15 from
app/models/cart.rb It may help the rest of us see what may be wrong…
Cheers
Mohit

Here is the entire file:

class Cart
include Reloadable
attr_reader :items
def initialize
@items = []
end

def add_product(product)
existing_product = @items.find {|item| item.product == product}
if existing_product
existing_product.increment_quantity
else
@items << CartItem.new(product)
end
end

Stuart

On 6/8/06, Dark A. [email protected] wrote:

app/models/cart.rb:15: parse error, unexpected $, expecting kEND

might you have forgotten an end (closing the begin/rescue/else work)
statement?

On 6/8/06, Dark A. [email protected] wrote:

def add_product(product)
existing_product = @items.find {|item| item.product == product}
if existing_product
existing_product.increment_quantity
else
@items << CartItem.new(product)
end
end

aren’t you missing an end statement to close the Cart class?

guess not =)

Just figured it out. I was missing an end at the end of the file.

Stuart

So much for RadRails and it’s syntax checking :slight_smile:

Stuart

I was missing it , see my last post to see I found it.

Thanks
Stuart

Dark A. wrote:

        into a problem after fixing the cart to reflect
    work) statement?

It’s just keeeping you alert!! :stuck_out_tongue:
Cheers,
Mohit.

My apologies, it wasn’t my intention to be snippy and didn’t mean it
like
that. Thanks for pointing out that about delays though as it hadn’t
crossed
my mind. I just wanted to make sure it was understood that the problem
was
solved and appreciate everyone’s input.

Stuart

On 6/8/06, Dark A. [email protected] wrote:

I was missing it , see my last post to see I found it.

Kindly recall that there are posting delays. :slight_smile: He may have been
trying to be helpful and didn’t see the posting that you had found it
on your own because it hadn’t come through yet. No need to be snippy.
(Text does not carry tone very well, so if you weren’t intending to
be snippy, my apologies.)

-Curtis

I had this same problem and I find this really weird because I was using
the actual code supplied by the book and was getting the error. When I
added an extra “end” to the bottom of the file it worked. Can someone
tell me why this code works:

class Cart
attr_reader :items

def initialize
@items = []
end

def add_product(product)
current_item = @items.find {|item| item.product == product}
if current_item
current_item.increment_quantity
else
@items << CartItem.new(product)
end
end
end

It seems to me that there is one too many "end"s here.

Is that right? I am also a newb.

Thanksz!

   current_item.increment_quantity
  else
   @items << CartItem.new(product)
 end
end
end

It seems to me that there is one too many "end"s here.

Looks okay to me. The first “end” closes the “if-else” block
The second “end” closes the “def” method
The third “end” closes the “class” declaration

HI,
I have almost the same issue when I follow the 3rd Edtion.
but I verified the every type characters, there should be no mistakes.
Any one could help?

SyntaxError in StoreController#add_to_cart
D:/InstantRails/rails_apps/lzpback/app/models/cart.rb:14: syntax error,
unexpected kEND, expecting $end
RAILS_ROOT: D:/InstantRails/rails_apps/lzpback
Application Trace | Framework Trace | Full Trace
D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:380:in
load_without_new_constant_marking' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:380:inload_file’
D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:521:in
new_constants_in' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:379:inload_file’
D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:259:in
require_or_load' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:425:inload_missing_constant’
D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in
const_missing' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:92:inconst_missing’
D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:437:in
load_missing_constant' D:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:96:inconst_missing’
D:/InstantRails/rails_apps/lzpback/app/controllers/store_controller.rb:19:in
find_cart' D:/InstantRails/rails_apps/lzpback/app/controllers/store_controller.rb:9:inadd_to_cart’
Request
Parameters:
{“authenticity_token”=>“jp209H0whp2bnxAl+JiDhLx4clqJbMwei4Oz9eUyBwo=”,
“id”=>“2”}
Show session dump
Response
Headers:
{“Content-Type”=>"",
“Cache-Control”=>“no-cache”}
**** cart.rb file as following,

class Cart
attr_reader :items
def initialize
@items = []
end
def add_product(product)
current_item = @items.find {|item| item.product == product}
if current_item
current_item.increment_quantity
else
@items << CartItem.new(product)
end
end
end

On 17 May 2010 02:50, Orient F. [email protected] wrote:

**** cart.rb file as following,
else
@items << CartItem.new(product)
end
end
end

Are you absolutely certain that is the right cart.rb? Is that the
complete file? It looks ok to me.

Colin

clanlaw wrote:

On 17 May 2010 02:50, Orient F. [email protected] wrote:

**** cart.rb file as following,
� � � �else
� � � �@items << CartItem.new(product)
� � � �end
� �end
end

Are you absolutely certain that is the right cart.rb? Is that the
complete file? It looks ok to me.

Colin

Hi Colin,
it is, I am sure. I’m wondering is there anywhere else cause the
problem.
thanks for response!

I copied and pasted and ran this code and it worked fine for me. Any
stray “,” characters?

On 18 May 2010 05:04, Orient F. [email protected] wrote:

Are you absolutely certain that is the right cart.rb? Â Is that the
complete file? Â It looks ok to me.

Colin

Hi Colin,
it is, I am sure. I’m wondering is there anywhere else cause the
problem.

There is something odd going on. I suggest you comment out the
contents of the file and add bits back in till it fails. Maybe you
have an unprintable character that is causing the problem.

Colin

Colin L. wrote:

On 18 May 2010 05:04, Orient F. [email protected] wrote:

Are you absolutely certain that is the right cart.rb? Â Is that the
complete file? Â It looks ok to me.

Colin

Hi Colin,
it is, I am sure. I’m wondering is there anywhere else cause the
problem.

There is something odd going on. I suggest you comment out the
contents of the file and add bits back in till it fails. Maybe you
have an unprintable character that is causing the problem.

Colin

hi Colin
I solved the problem, it’s because I use the utf8 encoding for the new
*.rb file. the default is the ANSI encoding.
Thanks for you response