Prev | Current Page 557 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"

new {|a| a.create_step == 2 })
For more information regarding validations, see Chapter 4.
validates_length_of(*attribute_names)
This method adds errors to the specified attributes if the attribute??™s values do not match the
specified restrictions on length:
class Account < ActiveRecord::Base
validates_length_of :first_name, :maximum => 30
end
The validates_length_of method takes only one length-check operation. Valid operations
are :minimum, :maximum, :is, :within, and :in.
The :minimum operation checks whether the attribute is longer than the specified minimum
length. Either :message or :too_short can be used to customize the error message when this
check is used. The default is "is too short (minimum is %d characters)".
APPENDIX ?–  ACTIVE RECORD METHODS IN DETAIL 262
validates_length_of(:first_name, :minimum => 5, :message => "is too short")
The :maximum operation checks whether the attribute is shorter than the specified maximum
length. Either :message or :too_long can be used to customize the error message when
this check is used.


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