1 class SpeechBalloon < ActiveRecord::Base
2 has_many :balloons, :dependent => :destroy
3 has_many :speeches, :dependent => :destroy
4 belongs_to :speech_balloon_template
7 accepts_nested_attributes_for :balloons
8 accepts_nested_attributes_for :speeches
10 validates :panel_id, :presence => true, :numericality => true, :existence => true
11 validates :speech_balloon_template_id, :presence => true, :numericality => true, :existence => true
12 validates :classname, :presence => true, :length => {:maximum => 50}
13 validates :z, :presence => true, :numericality => {:greater_than => 0}
14 validates :t, :presence => true, :numericality => {:greater_than_or_equal_to => 0}
15 # validates :settings, :presence => true
17 before_create :supply_t
20 self.t = SpeechBalloon.maximum(:t).to_i + 1