OSDN Git Service

t#31085:raise err when input invalid encoding string
[pettanr/pettanr.git] / app / models / author.rb
index 3fd96ec..b234a79 100644 (file)
@@ -7,6 +7,15 @@ class Author < ActiveRecord::Base
   validates :name, :presence => true, :length => {:maximum => 30}
   validates :user_id, :numericality => true, :existence => {:both => false}
   
+  before_validation :valid_encode
+  
+  def valid_encode
+    ['name'].each do |a|
+      next if attributes[a] == nil
+      raise Pettanr::BadRequest unless attributes[a].valid_encoding?
+    end
+  end
+  
   def supply_default
     self.name = 'no name' if self.name.blank?
   end