Forum: Ruby on Rails Agile Web Dev (book) question: errors

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Dark Ambient (Guest)
on 2006-06-08 18:15
(Received via mailing list)
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
Mohit Sindhwani (Guest)
on 2006-06-08 18:19
(Received via mailing list)
Dark Ambient 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
Dark Ambient (Guest)
on 2006-06-08 18:22
(Received via mailing list)
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
unknown (Guest)
on 2006-06-08 18:28
(Received via mailing list)
On 6/8/06, Dark Ambient <sambient@gmail.com> wrote:
> app/models/cart.rb:15: parse error, unexpected $, expecting kEND
>
>
might you have forgotten an end (closing the begin/rescue/else work)
statement?
unknown (Guest)
on 2006-06-08 18:31
(Received via mailing list)
On 6/8/06, Dark Ambient <sambient@gmail.com> 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?
unknown (Guest)
on 2006-06-08 18:31
(Received via mailing list)
guess not =)
Dark Ambient (Guest)
on 2006-06-08 18:38
(Received via mailing list)
Just figured it out.  I was missing an end at the end of the file.

Stuart
Dark Ambient (Guest)
on 2006-06-08 18:41
(Received via mailing list)
So much for RadRails and it's syntax checking :)

Stuart
Mohit Sindhwani (Guest)
on 2006-06-08 18:48
(Received via mailing list)
Dark Ambient wrote:
>
>             into a problem after fixing the cart to reflect
>         work) statement?
>
>
>
>

It's just keeeping you alert!!  :P
Cheers,
Mohit.
Dark Ambient (Guest)
on 2006-06-08 19:16
(Received via mailing list)
I was missing it , see my last post to see I found it.

Thanks
Stuart
91577d00348e23566f04e26438ace241?d=identicon&s=25 Curtis S. (cuspendlove)
on 2006-06-08 19:29
(Received via mailing list)
On 6/8/06, Dark Ambient <sambient@gmail.com> wrote:
> 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.)

-Curtis
Dark Ambient (Guest)
on 2006-06-08 19:42
(Received via mailing list)
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
2b61a96f5a53900eba84afa1d6b37881?d=identicon&s=25 Lee M. (electricorange)
on 2010-01-16 04:00
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!
E. Litwin (Guest)
on 2010-01-16 05:01
(Received via mailing list)
>       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
6af218fd65551fc98baf52a6a173f974?d=identicon&s=25 Orient F. (orientfang)
on 2010-05-17 03:50
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:in
`load_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:in
`load_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:in
`load_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:in
`const_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:in
`const_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:in
`add_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
clanlaw (Guest)
on 2010-05-17 22:58
(Received via mailing list)
On 17 May 2010 02:50, Orient Fang <lists@ruby-forum.com> 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
6af218fd65551fc98baf52a6a173f974?d=identicon&s=25 Orient F. (orientfang)
on 2010-05-18 06:04
clanlaw wrote:
> On 17 May 2010 02:50, Orient Fang <lists@ruby-forum.com> 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!
frogstarr78 (Guest)
on 2010-05-18 07:12
(Received via mailing list)
I copied and pasted and ran this code and it worked fine for me. Any
stray "," characters?
Colin Law (Guest)
on 2010-05-18 10:04
(Received via mailing list)
On 18 May 2010 05:04, Orient Fang <lists@ruby-forum.com> 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
6af218fd65551fc98baf52a6a173f974?d=identicon&s=25 Orient F. (orientfang)
on 2010-05-21 07:13
Colin Law wrote:
> On 18 May 2010 05:04, Orient Fang <lists@ruby-forum.com> 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
This topic is locked and can not be replied to.