Skip to content

Instantly share code, notes, and snippets.

@mokolabs
Created April 20, 2011 16:52
Show Gist options
  • Save mokolabs/931887 to your computer and use it in GitHub Desktop.
Save mokolabs/931887 to your computer and use it in GitHub Desktop.
# CONTROLLER
# Recent comments on theaters
comments = Comment.find(:all, :conditions => "entity_type = 'Theater'", :order => "id DESC", :select => "entity_id", :limit => 100)
comments = comments.map{ |i| i.entity_id }.uniq
theaters = Theater.find(:all, :conditions => "id IN (#{comments.join(',')})")
@theaters_with_comments = theaters.sort_by{|e| comments.index(e.id)}
# VIEW
%h2 Recent comments
%ul
- @theaters_with_comments[0..9].each do |theater|
%li= link_to theater.name, theater_path(theater)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment