ecole_eft_app/app/models/table_content.rb
Nicolas Bally ba02bda008 suite
2021-05-15 02:43:48 +02:00

49 lines
868 B
Ruby

# -*- encoding : utf-8 -*-
class TableContent < ActiveRecord::Base
has_one :portlet, :as => :content, :dependent => :destroy
has_many :table_rows #, :include => :cel_tables, :order => :position
has_many :cel_tables, :through => :table_rows
STYLES = [["avec bordures",1],["sans bordures",2]]
after_create do
self.nbr_rows.to_i.times do
table_row = TableRow.create(:position => 1, :table_content_id => self.id)
self.nbr_cols.to_i.times do
cel_table = CelTable.new
table_row.cel_tables << cel_table
end
end
end
def dup
@new = TableContent.new(self.attributes)
@new.id = nil
@new.save
@new.table_rows.destroy_all
self.table_rows.each do |table_row|
new_tr = table_row.dup
new_tr.table_content = @new
new_tr.save
end
@new
end
end