Nestor Marchante
2006-Apr-11 22:44 UTC
[Rails] Variable not evaluating, returning nil object
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? <%=image_tag(thumbnail(items[b].catalognum, 192),:alt=>items[b].view_description,:border=>0)%> If I change it to: <%=image_tag(thumbnail(items[0].catalognum, 192),:alt=>items[0].view_description,:border=>0)%> 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060411/ee45f948/attachment-0001.html
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 http://9cays.com On 12/04/2006, at 8:43 AM, Nestor Marchante wrote:> 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? > > > <%=image_tag(thumbnail(items[b].catalognum, 192),:alt=>items > [b].view_description,:border=>0)%> > > > If I change it to: > > > <%=image_tag(thumbnail(items[0].catalognum, 192),:alt=>items > [0].view_description,:border=>0)%> > > > 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?