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