Skip to content

Instantly share code, notes, and snippets.

@pi3r
Created September 5, 2012 15:09
Show Gist options
  • Save pi3r/3638065 to your computer and use it in GitHub Desktop.
Save pi3r/3638065 to your computer and use it in GitHub Desktop.
module SeoContentable
extend ActiveSupport::Concern
included do
SeoContent.add_seo_contentable_type(self.name) # Register class name
end
# Public: Find the SeoContent based on the current class.name and id.
#
# Returns an SeoContent or nil.
def seo_content
@seo_content ||= SeoContent.
find_by_seo_contentable_type_and_seo_contentable_id(self.class.name, self.id)
end
end
# Model
class SeoContent < ActiveRecord::Base
@@contentable_types = []
def self.add_seo_contentable_type(add_seo_contentable_type)
@@contentable_types << add_seo_contentable_type unless @@contentable_types.include?(add_seo_contentable_type)
end
def self.seo_contentable_types
@@contentable_types
end
end
class AnyClass
include SeoContentable
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment