Forum: Ruby on Rails Variable not evaluating, returning nil object

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
888c4f0ea8bd4c0da99057f627c2984b?d=identicon&s=25 Nestor Marchante (Guest)
on 2006-04-12 00:47
(Received via mailing list)
There is probably a simple answer to this, but I'm fairly new to rails.

Any idea why the variable "b" won't evaluate on this line?


If I change it to:


It works fine, and if I append the value of b at the end it prints on
the screen as the correct value (0). But, it's insisting that there is a
nil object.

"You have a nil object when you didn't expect it!
The error occured while evaluating nil.catalognum"

Thank you,

Nestor Marchante
C9c7a65848f13e2b1a226bbe43bc3672?d=identicon&s=25 Pete Yandell (pete)
on 2006-04-12 01:45
(Received via mailing list)
That doesn't tell you that b is nil; that tells you that items[b] is
nil. Are you absolutely sure that the value of b is an integer zero?
It could, for example, be the string "0"? What if you change items[b]
to items[b.to_i]?

Pete Yandell
This topic is locked and can not be replied to.