Enumerator sort_failing when item nil

J

joss

I am sorting an Array of items w:

@buddies = @user.buddies.compact.sort_by {|item| item.send @criteria}

i get the results when the item criteria is not nil ( 'display_name',
'email',...)
"display_name"=>"pansart"
"email"=>"(e-mail address removed)"

but some of the items have "last_name"=>nil

and when I try to sort on it , I get an error

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.<=>

is there anyway to get it sorted ?

additional question (linked to this one obviously...): how to
downcase an item attribute before sorting on it (some display_name
are capitalized other non-capitalized

thanks for your help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
DewittMill
Top