# -*- encoding : utf-8 -*- class BlockContent < ActiveRecord::Base belongs_to :image_file has_one :portlet, :as => :content, :dependent => :destroy has_many :blocks, :as => :blockable, :dependent => :destroy validates :nbr_columns, :presence => true STYLES = [["normal",1],["Blanc encadré",2],["centré",3]] before_create do self.row1 = self.row2 = self.row3 = self.row4 = 12/self.nbr_columns.to_i end def row1_value self.row1.to_i end def row2_value self.row1.to_i+self.row2.to_i end def row3_value self.row1.to_i+self.row2.to_i+self.row3.to_i end def row4_value self.row1.to_i+self.row2.to_i+self.row3.to_i+self.row4.to_i end def dup @new = BlockContent.new(self.attributes) @new.id = nil @new.save self.blocks.each do |block| new_b = block.dup new_b.blockable = @new new_b.save end @new end def self.picto "columns" end end