Prev | Current Page 548 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"

add_on_empty %w( first_name last_name )
end
end
For more information regarding validations, see Chapter 4.
validates_acceptance_of(*attribute_names)
This method is used to validate that an attribute value when you do not want to store the
attribute as an actual column in the database. This would typically be used for an acceptance
of terms check box on a web page.
class Account < ActiveRecord::Base
validates_acceptance_of :terms_of_service
end
The preceding class definition adds a virtual terms_of_service attribute to the Account
class. The terms_of_service attribute is not represented by a column in the database.
In addition to the virtual attributes to create, this method takes the configuration options
of :message, :on, :accept, or :if.
The :message option provides a custom error message. The default error message is "must
be accepted":
validates_acceptance_of :terms_of_service, :message => "must be verified"
The :on option specifies for what methods this validation should be active. Valid options
are :save, :create, and :update.


Pages:
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560