diff options
author | Vijay Dev <vijaydev.cse@gmail.com> | 2011-05-25 22:08:14 +0530 |
---|---|---|
committer | Vijay Dev <vijaydev.cse@gmail.com> | 2011-05-25 22:17:36 +0530 |
commit | 492f60672c91a1fb9bab1c16a941f87c26444ac8 (patch) | |
tree | 23c0caadb93719a9abbc6c20ea1bea38177e04cf /railties/guides/source/active_record_validations_callbacks.textile | |
parent | f69d5cddf0d05388685b64d42cfa50bbca5b4b80 (diff) | |
download | rails-492f60672c91a1fb9bab1c16a941f87c26444ac8.tar.gz rails-492f60672c91a1fb9bab1c16a941f87c26444ac8.tar.bz2 rails-492f60672c91a1fb9bab1c16a941f87c26444ac8.zip |
changes validates_format & numericality to newer syntax
Diffstat (limited to 'railties/guides/source/active_record_validations_callbacks.textile')
-rw-r--r-- | railties/guides/source/active_record_validations_callbacks.textile | 12 |
1 files changed, 6 insertions, 6 deletions
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 <ruby> 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 </ruby> @@ -336,8 +336,8 @@ WARNING. Note that the regular expression above allows a trailing newline charac <ruby> 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 </ruby> @@ -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 <ruby> class Product < ActiveRecord::Base validates :description, :value, :presence => true - validates_numericality_of :value, :allow_nil => true + validates :value, :numericality => true, :allow_nil => true end </ruby> |