Sha256: 1a272b6e5e39c1445738ae0b938868a2cf56ec0c6ae4d6df748cfc0cded6ca72

Contents?: true

Size: 981 Bytes

Versions: 23

Compression:

Stored size: 981 Bytes

Contents

module Virgo
  class PageModule < ActiveRecord::Base
    mount_uploader :image, Virgo::ImageUploader

    attr_accessor :subject_headline # form hook

    before_save :derive_template_path

    validates :name, presence: true

    belongs_to :subject, polymorphic: true

    has_many :page_module_posts
    has_many :posts, through: :page_module_posts

    scope :enabled, ->{ where(enabled: true) }

    scope :visible_to_admins, ->{ where(hidden_from_admins: false) }

    after_save :expire_site_key

    def self.POPULAR
      @_popular ||= find_by(name: 'popular posts')
    end

    def admin_image_path
      "virgo/admin/page_modules/#{name.downcase.gsub(' ', '_').gsub('-', '_')}.png"
    end

    def subject_headline
      subject.try :headline
    end

    private

    def derive_template_path(opts={})
      if name_changed? || opts[:force]
        self.template_path = "/virgo/page_modules/#{name.downcase.gsub(' ', '_').gsub('-', '_')}"
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
virgo-0.2.7 app/models/virgo/page_module.rb
virgo-0.2.6 app/models/virgo/page_module.rb
virgo-0.2.5 app/models/virgo/page_module.rb
virgo-0.2.4 app/models/virgo/page_module.rb
virgo-0.2.2 app/models/virgo/page_module.rb
virgo-0.2.1 app/models/virgo/page_module.rb
virgo-0.2 app/models/virgo/page_module.rb
virgo-0.1.16 app/models/virgo/page_module.rb
virgo-0.1.15 app/models/virgo/page_module.rb
virgo-0.1.14 app/models/virgo/page_module.rb
virgo-0.1.13 app/models/virgo/page_module.rb
virgo-0.1.12 app/models/virgo/page_module.rb
virgo-0.1.11 app/models/virgo/page_module.rb
virgo-0.1.10 app/models/virgo/page_module.rb
virgo-0.1.8 app/models/virgo/page_module.rb
virgo-0.1.7 app/models/virgo/page_module.rb
virgo-0.1.6 app/models/virgo/page_module.rb
virgo-0.1.5 app/models/virgo/page_module.rb
virgo-0.1.4 app/models/virgo/page_module.rb
virgo-0.1.3 app/models/virgo/page_module.rb