Skip to content

Instantly share code, notes, and snippets.

@byroot
Created April 5, 2011 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save byroot/904459 to your computer and use it in GitHub Desktop.
Save byroot/904459 to your computer and use it in GitHub Desktop.
class Recette < AR::Base
include Feeds::ModelMixin
end
class Article < AR::Base
include Feeds::ModelMixin
end
module Feeds
module ModelMixin
def self.included(base)
base.after_create(:create_feed_item)
end
def create_feed_item
model = "Feeds::#{self.class.name}Item".constantize
model.create!(
:created_at => created_at # etc
)
end
end
class Item < AR::Base
abstract = true
# field created_at
end
class RecetteItem
has_one :recette, :column => :attachable_id
end
class ArticleItem
has_one :article, :column => :attachable_id
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment