On 21 February 2010 21:27, RubyonRails_newbie
<[email protected]> wrote:
>   �...@users = infos.collect { |info| info.user }
>
> For some odd reason, when I click the letter 'B' It throws an
> exception: You have a nil object when you didn't expect it!
> The error occurred while evaluating nil.info
>

That's not an inconsistent nomethod error... if *every* time you click
"B" it throws, it's a *very* consistent one!

It's telling you, right there on the screen, that one of the values in
the @users array is nil, and nil objects don't have an "info" method.

Have a rummage through the methods for Array [1] when you have
downtime, and spot what the "compact" method does... I think it'll
sort you out (if you amend your controller thus :-)

@users = infos.collect { |info| info.user }.compact


[1] http://ruby-doc.org/core/classes/Array.html  Whenever I get stuck,
I'm straight onto Google with "ruby api [classname]" to bring me
straight to the reference page that should get me on the right track
again ("sometime it's "Rails api [classname/methodname]" if the thing
I'm messing with isn't pure Ruby.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to