Sha256: da8ceb2bf673f37e5f2415bb6f19c9806ad606531be598c0ece199ba732fe36d

Contents?: true

Size: 1.02 KB

Versions: 19

Compression:

Stored size: 1.02 KB

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, class_name: 'Virgo::PageModulePost'
    has_many :posts, through: :page_module_posts, class_name: 'Virgo::Post'

    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

19 entries across 19 versions & 1 rubygems

Version Path
virgo-0.3.17 app/models/virgo/page_module.rb
virgo-0.3.16 app/models/virgo/page_module.rb
virgo-0.3.15 app/models/virgo/page_module.rb
virgo-0.3.14 app/models/virgo/page_module.rb
virgo-0.3.13 app/models/virgo/page_module.rb
virgo-0.3.12 app/models/virgo/page_module.rb
virgo-0.3.11 app/models/virgo/page_module.rb
virgo-0.3.10 app/models/virgo/page_module.rb
virgo-0.3.9 app/models/virgo/page_module.rb
virgo-0.3.8 app/models/virgo/page_module.rb
virgo-0.3.7 app/models/virgo/page_module.rb
virgo-0.3.6 app/models/virgo/page_module.rb
virgo-0.3.4 app/models/virgo/page_module.rb
virgo-0.3.3 app/models/virgo/page_module.rb
virgo-0.3.2 app/models/virgo/page_module.rb
virgo-0.3.1 app/models/virgo/page_module.rb
virgo-0.3 app/models/virgo/page_module.rb
virgo-0.2.9 app/models/virgo/page_module.rb
virgo-0.2.8 app/models/virgo/page_module.rb