OSDN Git Service

add natural number validater
[pettanr/pettanr.git] / lib / validators / natural_number_validator.rb
diff --git a/lib/validators/natural_number_validator.rb b/lib/validators/natural_number_validator.rb
new file mode 100644 (file)
index 0000000..cd918c2
--- /dev/null
@@ -0,0 +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
+  end\r
+end\r
+