Sha256: 4bedfeec4497e05919cfc864a961561c2e7fe60b095bf0fc1c24c3614104a180

Contents?: true

Size: 918 Bytes

Versions: 2

Compression:

Stored size: 918 Bytes

Contents

module Georgia
	class Widget < ActiveRecord::Base

    include Concerns::Contentable

    has_many :ui_associations, dependent: :destroy
    has_many :ui_sections, through: :ui_associations
    has_many :revisions, through: :ui_associations
    has_many :pages, through: :revisions

    scope :footer, joins(:ui_sections).where(georgia_ui_sections: {name: 'Footer'}).uniq
    scope :submenu, joins(:ui_sections).where(georgia_ui_sections: {name: 'Submenu'}).uniq
    scope :sidebar, joins(:ui_sections).where(georgia_ui_sections: {name: 'Sidebar'}).uniq

    validate :content_presence

    def content_presence
      contents.each do |content|
        errors.add(:base, I18n.t("locales.#{content.locale}") + ' Title is required.') unless content.title.present?
      end
    end

    def featured?
      @featured ||= pages.any?
    end

    def featured_count
      @featured_count ||= pages.count
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
georgia-0.7.8 app/models/georgia/widget.rb
georgia-0.7.7 app/models/georgia/widget.rb