OSDN Git Service
(root)
/
pettanr
/
pettanr.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
| inline |
side by side
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
+++ b/
lib/validators/natural_number_validator.rb
@@ -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
+