OSDN Git Service

t#30307:change valid message for custom validator
authoryasushiito <yas@pen-chan.jp>
Thu, 13 Dec 2012 09:34:24 +0000 (18:34 +0900)
committeryasushiito <yas@pen-chan.jp>
Thu, 13 Dec 2012 09:34:24 +0000 (18:34 +0900)
config/locales/ja.yml
lib/validators/natural_number_validator.rb
lib/validators/not_zero_validator.rb
lib/validators/resize_validator.rb
lib/validators/reverse_validator.rb
lib/validators/sync_vh_validator.rb

index d212534..2a201d4 100644 (file)
@@ -121,6 +121,11 @@ ja:
       wrong_length: は%{count}文字で入力してください。
       existence: は存在しません。
       url: はurlの書式で入力してください。
+      natural_number: は1以上の数値で入力してください。
+      not_zero: は0以外の数値で入力してください。
+      resize: はサイズを変更できません。
+      reverse: は反転できません。
+      sync_vh: は縦横比を変更できません。
     template:
       body: 次の項目を確認してください。
       header:
index cd918c2..ce6db91 100644 (file)
@@ -1,6 +1,6 @@
 class NaturalNumberValidator < ActiveModel::EachValidator\r
   def validate_each(record, attribute, value)\r
-    record.errors[attribute] << (options[:message] || "is not natural number") if value.to_i < 1\r
+    record.errors[attribute] << (options[:message] || I18n.t('activerecord.errors.messages.natural_number')) if value.to_i < 1\r
   end\r
 end\r
-
+\r
index 8d4389b..b65d807 100644 (file)
@@ -1,6 +1,6 @@
 class NotZeroValidator < ActiveModel::EachValidator\r
   def validate_each(record, attribute, value)\r
-    record.errors[attribute] << (options[:message] || "is zero") if value.to_i == 0\r
+    record.errors[attribute] << (options[:message] || I18n.t('activerecord.errors.messages.not_zero')) if value.to_i == 0\r
   end\r
 end\r
-
+\r
index be01eeb..87f9704 100644 (file)
@@ -1,7 +1,7 @@
 class ResizeValidator < ActiveModel::EachValidator\r
   def validate_each(record, attribute, value)\r
     if record.picture and record.picture.flag_resize < 0\r
-      record.errors[attribute] << (options[:message] || "no resize") unless value == record.picture[attribute]\r
+      record.errors[attribute] << (options[:message] || I18n.t('activerecord.errors.messages.resize')) unless value == record.picture[attribute]\r
     end\r
   end\r
 end\r
index b52f697..4965fc8 100644 (file)
@@ -1,7 +1,7 @@
 class ReverseValidator < ActiveModel::EachValidator\r
   def validate_each(record, attribute, value)\r
     if record.picture and record.picture.flag_reverse < 0\r
-      record.errors[attribute] << (options[:message] || "no reverse") if value < 0\r
+      record.errors[attribute] << (options[:message] || I18n.t('activerecord.errors.messages.reverse')) if value < 0\r
     end\r
   end\r
 end\r
index 04425fd..92c3a07 100644 (file)
@@ -1,7 +1,7 @@
 class SyncVhValidator < ActiveModel::EachValidator\r
   def validate_each(record, attribute, value)\r
     if record.picture and record.picture.flag_sync_vh < 0\r
-      record.errors[attribute] << (options[:message] || "sync_vh") unless sync?(record)\r
+      record.errors[attribute] << (options[:message] || I18n.t('activerecord.errors.messages.sync_vh')) unless sync?(record)\r
     end\r
   end\r
   \r