Sha256: 5d17c22f88fdd3ad00df39ecb343e171bcecb87cdf5da0b7e563ba7e6932e084

Contents?: true

Size: 627 Bytes

Versions: 2

Compression:

Stored size: 627 Bytes

Contents

module Flms
  class Page < ActiveRecord::Base
    attr_accessible :title, :url

    has_many :blocks_pages, dependent: :destroy
    has_many :blocks, through: :blocks_pages

    validates :title, :url, presence: true

    # Returns the blocks_pages of this page, in the right order to display them.
    def ordered_blocks_pages
      blocks_pages.order('ordering').includes(:block)
    end

    # Returns the BlocksPage object for the given block on this page.
    def position_for_block block_id
      blocks_pages.where(block_id: block_id).first
    end

    # For creating URLs.
    def to_param
      url
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flms-0.0.3 app/models/flms/page.rb
flms-0.0.2 app/models/flms/page.rb