So I have a bunch of users, who all have user.dj\_name attributes. It's a validated necessity on the model, but I'm still being cautious here because I'm running into problems.

I want to get a bunch of users, then order them by their dj\_name. Something like this:

```
@djs = Event.all.map { |e| e.program.user }.sort_by {|x,y| x.dj_name <=> y.dj_name }

```

where it's pulling all DJs who have Events (shows). It fails with "NoMethodError: undefined method `dj\_name' for nil:NilClass"

So I tried:

```
@djs = Event.all.map { |e| e.program.user }
@djs.compact.sort_by! {|x,y| x.dj_name <=> y.dj_name rescue nil}

```

And it doesn't sort. Without the "rescue nil" clause, I get the same error.

And if I do a reject! if the object is nil I get nothing.

```
> @djs.reject! {|d| d.nil? }
=> nil 

```

It seems like none of the objects in the array are nil, the sorting mechanism is giving me errors, and rescuing it just stops the sorting process and returns an unchanged array.

halp?