OSDN Git Service

t#31535::speech_balloon has one :speech and balloon
[pettanr/pettanr.git] / app / models / speech_balloon.rb
index 92d7f9e..4ff7934 100644 (file)
@@ -1,11 +1,11 @@
 class SpeechBalloon < ActiveRecord::Base
-  has_many :balloons, :dependent => :destroy
-  has_many :speeches, :dependent => :destroy
+  has_one :balloon, :dependent => :destroy
+  has_one :speech, :dependent => :destroy
   belongs_to :speech_balloon_template
   belongs_to :panel
   
-  accepts_nested_attributes_for :balloons
-  accepts_nested_attributes_for :speeches
+  accepts_nested_attributes_for :balloon
+  accepts_nested_attributes_for :speech
   
   validates :panel_id, :numericality => {:allow_blank => true}
   validates :speech_balloon_template_id, :presence => true, :numericality => true, :existence => {:both => false}
@@ -73,11 +73,11 @@ class SpeechBalloon < ActiveRecord::Base
   end
   
   def self.list_opt
-    {:include => {:panel => {:author => {}}, :balloons => {}, :speeches => {}, :speech_balloon_template => {} }}
+    {:include => {:panel => {:author => {}}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }}
   end
   
   def self.list_json_opt
-    {:include => {:panel => {:include => {:author => {} }}, :balloons => {}, :speeches => {}, :speech_balloon_template => {} }}
+    {:include => {:panel => {:include => {:author => {} }}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }}
   end
   
   def self.show cid, au
@@ -89,21 +89,21 @@ class SpeechBalloon < ActiveRecord::Base
   end
   
   def self.show_opt
-    {:include => {:panel => {:author => {}}, :balloons => {}, :speeches => {}, :speech_balloon_template => {} }}
+    {:include => {:panel => {:author => {}}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }}
   end
   
   def self.show_json_opt
-    {:include => {:panel => {:include => {:author => {} }}, :balloons => {}, :speeches => {}, :speech_balloon_template => {} }}
+    {:include => {:panel => {:include => {:author => {} }}, :balloon => {}, :speech => {}, :speech_balloon_template => {} }}
   end
   
   def scenario
-    balloons.first.scenario.to_s + 
-    speeches.map {|s| s.scenario }.join
+    ERB::Util.html_escape(self.caption.to_s) + self.balloon.scenario.to_s + 
+    self.speech.scenario.to_s
   end
   
   def plain_scenario
-    balloons.first.plain_scenario.to_s + 
-    speeches.map {|s| s.plain_scenario }.join
+    self.caption.to_s + self.balloon.plain_scenario.to_s + 
+    self.speech.plain_scenario.to_s
   end
   
 end