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:
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.
I was missing it , see my last post to see I found it.
Kindly recall that there are posting delays. 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.)
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.
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?
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
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.
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.