views:

16

answers:

1

Here is how I created an array:

@companies_with_email = Company.contact_emails_date_sent_gt(@monday).
                                contact_emails_date_sent_lt(@friday).
                                find(:all, :select => "distinct companies.* ") || []

@companies_with_call = Company.contact_calls_date_sent_gt(@monday).
                                contact_calls_date_sent_lt(@friday).
                                find(:all, :select => "distinct companies.* ") || []

@companies_with_activity = @companies_with_email + @companies_with_call
@companies_with_activity.uniq!

However, I want it to be in alphabetical order, so I tried to add .sort! and I got an error saying <=> method doesn't exist.

undefined method `<=>' for #<Company:0x9d506a8>
+4  A: 

Sorting companies doesn't "just work". What that error message means is that there is no way to just compare (use the comparison operator <=>, in this case) two companies, since it doesn't know what you would compare: ID in database, name, ID in Ruby memory, etc.

You can define sorting behavior yourself, though:

@companies_with_activity.sort! { |a,b| a.name <=> b.name }
Matchu
fantastic that's just right on
Angela