Skip to content

Instantly share code, notes, and snippets.

@dewski
Created October 30, 2009 20:41
Show Gist options
  • Select an option

  • Save dewski/222701 to your computer and use it in GitHub Desktop.

Select an option

Save dewski/222701 to your computer and use it in GitHub Desktop.
class HomeController < ApplicationController
def index
feeds = Feed.find(:all,
:conditions => ['created_at > ?', 5.days.ago],
:order => 'created_at DESC',
:limit => 15)
# We now need to put each one into instance variable
@items = feeds.collect do |item|
# Translates to Comment.find(1), Connection.find(1), etc.
# item_type returns a string that you can then initiate the model
# and call any methods you normally would on it
{ :content => item.feedable_type.constantize.find(item.feedable_id),
:item => item }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment