Prev | Current Page 547 | 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
Additionally, it is possible to supply validation method names with the nonblock form of
this method:
class Account < ActiveRecord::Base
protected
validate_on_create :check_names
def check_names
errors.add_on_empty %w( first_name last_name )
end
end
For more information regarding validations, see Chapter 4.
APPENDIX ?–  ACTIVE RECORD METHODS IN DETAIL 256
validate_on_update(*methods, &block)
The validate_on_update method is overridden in an Active Record class and is called only
before an existing record of that class is saved. In the example Account class that follows, each
time an existing Account record is saved, the first_name and last_name attributes will be
checked to make sure they are not empty:
class Account < ActiveRecord::Base
protected
def validate_on_update
errors.add_on_empty %w( first_name last_name )
end
end
Additionally, it is possible to supply validation method names with the nonblock form of
this method:
class Account < ActiveRecord::Base
protected
validate_on_update :check_names
def check_names
errors.


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