Sha256: 97178ec983a05b2d4ca36baee9984421776752cc86d30c44500677967d975897

Contents?: true

Size: 717 Bytes

Versions: 1

Compression:

Stored size: 717 Bytes

Contents

require 'active_support/concern'

module Georgia
  module Concerns
    module Contentable
      extend ActiveSupport::Concern

      included do
        has_many :contents, as: :contentable, dependent: :destroy, class_name: Georgia::Content
        accepts_nested_attributes_for :contents

        scope :with_locale, -> (locale) { joins(:contents).where(georgia_contents: {locale: locale}).uniq }

        def content(locale=nil)
          locale ||= I18n.locale.to_s
          @content ||= contents.select{|c| c.locale == locale}.first || Georgia::Content.new(locale: locale)
        end

        delegate :title, :text, :excerpt, :keywords, :keyword_list, :image, :locale, to: :content
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
georgia-0.8.0 app/models/georgia/concerns/contentable.rb