Forum: Ruby changing the type of a variable

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.
Allison N. (Guest)
on 2006-05-10 23:02
Hi,

I'm a ruby newbie, although I'm a programmer with 10yrs experience.  I
was running myself through the tutorial in Agile Web D. With
Rails, when I ran into a problem.  somewhere in the code I mistakenly
entered

@items = 0

instead of

@items = []

A bit later I tried the following

@items << LineItem.for_product(product)

but when i try to execute this code I got the following error:

"cannot convert LineItem to Integer"

Looking back through the code, I found the error mentioned above, and
corrected it.  However, Rails still insists that @items is an Integer.
Can anyone suggest what has gone wrong, or what I can do to fix it?

Alli
Allison N. (Guest)
on 2006-05-10 23:04
Oh, btw; I have just registered myself under the pseudo "demallien"...
Leslie V. (Guest)
on 2006-05-11 00:08
(Received via mailing list)
On 5/10/06, Allison N. <removed_email_address@domain.invalid> wrote:
>
> Looking back through the code, I found the error mentioned above, and
> corrected it.  However, Rails still insists that @items is an Integer.
> Can anyone suggest what has gone wrong, or what I can do to fix it?

If you have restarted webrick, you are probably setting @items to an
integer somewhere else.

If you have grep, you might want to grep for '@items', in your app or
controllers directory and look at each assignment. There might be
another place where you say @items = 0 or @items =
<some_object_that's_an_integer>

L
Daniel B. (Guest)
on 2006-05-11 04:33
(Received via mailing list)
Allison N. wrote:
> Oh, btw; I have just registered myself under the pseudo "demallien"...
>

And here I was hoping for "femalien".  Oh, well. ;)

Dan
Esteban Manchado =?iso-8859-1?Q?Vel=E1zquez?= (Guest)
on 2006-05-14 20:06
(Received via mailing list)
On Thu, May 11, 2006 at 04:02:39AM +0900, Allison N. wrote:
>
> Looking back through the code, I found the error mentioned above, and
> corrected it.  However, Rails still insists that @items is an Integer.
> Can anyone suggest what has gone wrong, or what I can do to fix it?

    Make sure you have actually changed all the "@items = 0" occurrences
in
the code to the correct version, and also make sure that you aren't
passing
around (through a form) any "items" variable to the value "0".

    Are those two lines in some controller action? It's not clear
whether
they are, or if you're using some external library or something... :-/
This topic is locked and can not be replied to.