I have this method which I want me to fetch the most recent activity_id for the corresponding user_id from the model UserActivity that keeps track of all the user activities and from that get the description of the activity_id from another model Activity.
The function works fine but at times throws bugs as "Not able to find activity_id". May be there could be a better way to implement this or Am I doing something wrong here ?
def last_activity(date, user_id)
  active_id = UserActivity.find(:all, :conditions => ["Date(updated_at) <= ? and user_id = ?", date, user_id]).last.activity_id
  text = Activity.find(active_id).description
end
The Schema of the model UserActivity is as follows :

Please help me get this fixed. Thanks !!
Ruby version 1.8.7, Rails 2.1.2
 
     
     
    