OSDN Git Service

t#31085:raise err when input invalid encoding string
[pettanr/pettanr.git] / app / models / comic.rb
index c60e519..dd78a40 100644 (file)
@@ -5,6 +5,14 @@ class Comic < ActiveRecord::Base
   
   validates :title, :presence => true, :length => {:maximum => 100}
   validates :visible, :presence => true, :numericality => true, :inclusion => {:in => 0..1}
+  before_validation :valid_encode
+  
+  def valid_encode
+    ['title'].each do |a|
+      next if attributes[a] == nil
+      raise Pettanr::BadRequest unless attributes[a].valid_encoding?
+    end
+  end
   
   def supply_default
     self.visible = 0 if self.visible.blank?