Created
September 5, 2012 15:09
-
-
Save pi3r/3638065 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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