Prev | Current Page 560 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"


The :only_integer option specifies that we are only looking for integers, not floats. The
default is :only_integer => false. When this option is used, the attribute value is matched
against the regular expression /^[+\-]?\d+$/ instead of using Kernel.Float.
The :on option specifies for what methods this validation should be active. Valid options
are :save, :create, and :update. The default value is :save.
validates_numericality_of(:value, :on => :create)
The :message option provides a custom error message. The default error message is "is
not a number".
validates_numericality_of(:value, :message => "must be a number")
The :allow_nil option, if true, specifies that the validation should be skipped if the
attribute is nil:
validates_numericality_of(:value, :allow_nil => true)
The :if option specifies a method, proc, or string that is called in order to determine
whether the validation should occur at all:
validates_numericality_of(:value, :if => :check_value)
validates_numericality_of(:value, :if => "check_value")
validates_numericality_of(:value, :if => Proc.


Pages:
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572