I Love Ruby

Posted by Matt on May 16, 2008

In the application I’m currently developing a User has_many Jobs, and each Job has a bunch of nested resources. The application calls for a Dashboard, filled with the latest changes to any Job the currently logged-in user is assigned to.

Sounds difficult huh?


def self.get_latest_items_for(current_user)
  assigned_job_ids = current_user.jobs.collect(&:id)
  find(:all, :conditions => ["job_id in (?)", assigned_job_ids])
end

In order to get the currently logged-in user’s list I just do:


RecentItem.get_latest_items_for(current_user)

Simple, elegant, understandable, and concise.

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

Comments