I have a user control panel that generates an event log by merging
various things that can happen on the site. These are:
user joins
user receives invitation
user completes invitation
user refers someone
user referee activates account
So I want to merge these events into a single array and sort them. It
works well sorting by created_at. However, I do not have unique classes
for all of the events I want to merge (yeah, REST would have worked well
here). So when I populate the array I do this:
# create array of all events for the log
@events = []
@events << @user.invitations
@events << @user.pending_referrals
@events << @user.active_referrals
@events = @events.flatten!.sort_by {|x| x.created_at }.reverse
A pending_referral and active_referral are the same object,but pending
has an activated_at = nil and an active_referral has activated_at =
datetime. So, it is possible to sort this array by created_at OR
activated_at?