Sha256: ea30daf4f7ac3fb0fd7b1c1b93d88a0516f5de25f71b8bbe3bcbbe48c52a6210

Contents?: true

Size: 1.18 KB

Versions: 28

Compression:

Stored size: 1.18 KB

Contents

class Caboose::PageBlock < ActiveRecord::Base
  self.table_name = "page_blocks"
  
  belongs_to :page
  belongs_to :page_block_type  
  has_many :page_block_field_values
  attr_accessible :id, :page_id, :page_block_type_id, :sort_order
    
  def fields
    return page_block_type.fields
  end
  
  def field_value(name)    
    page_block_field_values.each do |fv|
      return fv.value if fv.page_block_field.name == name
    end
    return nil
  end
  
  def field_value_object(name)    
    page_block_field_values.each do |fv|
      #Caboose.log("fv = #{fv}")
      return fv if fv.page_block_field.name == name      
    end
    return nil
  end
  
  def self.create_field_values(block_id)
    block = self.find(block_id)
    block.page_block_type.fields.each do |f| 
      if block.field_value_object(f.name).nil?
        Caboose::PageBlockFieldValue.create(:page_block_id => block.id, :page_block_field_id => f.id, :value => f.default)
      end
    end
  end
  
  def render_from_function(empty_text = nil) 
    locals = OpenStruct.new(:block => self, :empty_text => empty_text)
    erb = ERB.new(page_block_type.render_function)
    return erb.result(locals.instance_eval { binding })
  end

end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
caboose-cms-0.3.42 app/models/caboose/page_block.rb
caboose-cms-0.3.41 app/models/caboose/page_block.rb
caboose-cms-0.3.40 app/models/caboose/page_block.rb
caboose-cms-0.3.39 app/models/caboose/page_block.rb
caboose-cms-0.3.38 app/models/caboose/page_block.rb
caboose-cms-0.3.37 app/models/caboose/page_block.rb
caboose-cms-0.3.36 app/models/caboose/page_block.rb
caboose-cms-0.3.35 app/models/caboose/page_block.rb
caboose-cms-0.3.34 app/models/caboose/page_block.rb
caboose-cms-0.3.33 app/models/caboose/page_block.rb
caboose-cms-0.3.32 app/models/caboose/page_block.rb
caboose-cms-0.3.31 app/models/caboose/page_block.rb
caboose-cms-0.3.30 app/models/caboose/page_block.rb
caboose-cms-0.3.29 app/models/caboose/page_block.rb
caboose-cms-0.3.28 app/models/caboose/page_block.rb
caboose-cms-0.3.27 app/models/caboose/page_block.rb
caboose-cms-0.3.26 app/models/caboose/page_block.rb
caboose-cms-0.3.25 app/models/caboose/page_block.rb
caboose-cms-0.3.24 app/models/caboose/page_block.rb
caboose-cms-0.3.23 app/models/caboose/page_block.rb