From 492f60672c91a1fb9bab1c16a941f87c26444ac8 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 25 May 2011 22:08:14 +0530 Subject: changes validates_format & numericality to newer syntax --- .../source/active_record_validations_callbacks.textile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index b6a2a10460..8721ca51c5 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -251,8 +251,8 @@ This helper validates the attributes' values by testing whether they match a giv class Product < ActiveRecord::Base - validates_format_of :legacy_code, :with => /\A[a-zA-Z]+\z/, - :message => "Only letters allowed" + validates :legacy_code, :format => { :with => /\A[a-zA-Z]+\z/, + :message => "Only letters allowed" } end @@ -336,8 +336,8 @@ WARNING. Note that the regular expression above allows a trailing newline charac class Player < ActiveRecord::Base - validates_numericality_of :points - validates_numericality_of :games_played, :only_integer => true + validates :points, :numericality => true + validates :games_played, :numericality => true, :only_integer => true end @@ -507,7 +507,7 @@ class Person < ActiveRecord::Base validates :email, :uniqueness => true, :on => :create # it will be possible to create the record with a non-numerical age - validates_numericality_of :age, :on => :update + validates :age, :numericality => true, :on => :update # the default (validates on both create and update) validates :name, :presence => true, :on => :save @@ -776,7 +776,7 @@ When creating a form with the +form_for+ helper, you can use the +error_messages class Product < ActiveRecord::Base validates :description, :value, :presence => true - validates_numericality_of :value, :allow_nil => true + validates :value, :numericality => true, :allow_nil => true end -- cgit v1.2.3