Sha256: 3666c590aef19135e5a3d5dc40c9104edb835504700a175ec5e90c35e573a0c1

Contents?: true

Size: 1 KB

Versions: 17

Compression:

Stored size: 1 KB

Contents

class CmsBlock < ActiveRecord::Base
  
  # -- Relationships --------------------------------------------------------
  belongs_to :cms_page
  
  # -- Validations ----------------------------------------------------------
  validates :label,
    :presence   => true,
    :uniqueness => { :scope => :cms_page_id }
  
  # -- Class Methods --------------------------------------------------------
  class << self
    # making sure that the correct class is initialized based on :type passed
    # primarily important for form processing
    def new_with_cast(*args, &block)
      if (h = args.first).is_a?(Hash) && (type = h[:type] || h['type']) && (klass = type.constantize) != self
        return klass.new(*args, &block)
      end
      new_without_cast(*args, &block)
    end
    alias_method_chain :new, :cast
    
    def initialize_or_find(cms_page, label)
      cms_page.cms_blocks.detect{ |b| b.label == label.to_s } ||
      self.new(:label => label.to_s, :type => self.name, :cms_page => cms_page)
    end
  end
  
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
comfortable_mexican_sofa-1.0.17 app/models/cms_block.rb
comfortable_mexican_sofa-1.0.16 app/models/cms_block.rb
comfortable_mexican_sofa-1.0.15 app/models/cms_block.rb
comfortable_mexican_sofa-1.0.14 app/models/cms_block.rb
comfortable_mexican_sofa-1.0.13 app/models/cms_block.rb
comfortable_mexican_sofa-1.0.12 app/models/cms_block.rb
comfortable_mexican_sofa-1.0.11 app/models/cms_block.rb
comfortable_mexican_sofa-1.0.10 app/models/cms_block.rb
comfortable_mexican_sofa-1.0.9 app/models/cms_block.rb
comfortable_mexican_sofa-1.0.7 app/models/cms_block.rb
comfortable_mexican_sofa-1.0.6 app/models/cms_block.rb
comfortable_mexican_sofa-1.0.5 app/models/cms_block.rb
comfortable_mexican_sofa-1.0.4 app/models/cms_block.rb
comfortable_mexican_sofa-1.0.3 app/models/cms_block.rb
comfortable_mexican_sofa-1.0.2 app/models/cms_block.rb
comfortable_mexican_sofa-1.0.1 app/models/cms_block.rb
comfortable_mexican_sofa-1.0.0 app/models/cms_block.rb