aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source/active_record_validations_callbacks.textile
diff options
context:
space:
mode:
authoreparreno <emili@eparreno.com>2010-11-15 19:21:40 +0100
committerXavier Noria <fxn@hashref.com>2010-11-21 03:29:43 +0100
commit3d377454dbeb9ab9fc0a4d491498c237e33e8d4b (patch)
treeeb472ff9c113bc07386cf0973e166b9abf14badb /railties/guides/source/active_record_validations_callbacks.textile
parentd5779efaf2375466ab557868e586b9dbd942abc1 (diff)
downloadrails-3d377454dbeb9ab9fc0a4d491498c237e33e8d4b.tar.gz
rails-3d377454dbeb9ab9fc0a4d491498c237e33e8d4b.tar.bz2
rails-3d377454dbeb9ab9fc0a4d491498c237e33e8d4b.zip
remove old school validations and replaced with new validates method. Pending: fix active_record guide
Diffstat (limited to 'railties/guides/source/active_record_validations_callbacks.textile')
-rw-r--r--railties/guides/source/active_record_validations_callbacks.textile18
1 files changed, 9 insertions, 9 deletions
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile
index f7ef33bc1f..2a6f0715a9 100644
--- a/railties/guides/source/active_record_validations_callbacks.textile
+++ b/railties/guides/source/active_record_validations_callbacks.textile
@@ -96,7 +96,7 @@ To verify whether or not an object is valid, Rails uses the +valid?+ method. You
<ruby>
class Person < ActiveRecord::Base
- validates_presence_of :name
+ validates :name, :presence => true
end
Person.create(:name => "John Doe").valid? # => true
@@ -109,7 +109,7 @@ Note that an object instantiated with +new+ will not report errors even if it's
<ruby>
class Person < ActiveRecord::Base
- validates_presence_of :name
+ validates :name, :presence => true
end
>> p = Person.new
@@ -147,7 +147,7 @@ This method is only useful _after_ validations have been run, because it only in
<ruby>
class Person < ActiveRecord::Base
- validates_presence_of :name
+ validates :name, :presence => true
end
>> Person.new.errors[:name].any? # => false
@@ -355,7 +355,7 @@ This helper validates that the specified attributes are not empty. It uses the +
<ruby>
class Person < ActiveRecord::Base
- validates_presence_of :name, :login, :email
+ validates :name, :presence => true, :login, :email
end
</ruby>
@@ -505,7 +505,7 @@ class Person < ActiveRecord::Base
validates_numericality_of :age, :on => :update
# the default (validates on both create and update)
- validates_presence_of :name, :on => :save
+ validates :name, :presence => true, :on => :save
end
</ruby>
@@ -603,7 +603,7 @@ Returns an OrderedHash with all errors. Each key is the attribute name and the v
<ruby>
class Person < ActiveRecord::Base
- validates_presence_of :name
+ validates :name, :presence => true
validates_length_of :name, :minimum => 3
end
@@ -623,7 +623,7 @@ h4(#working_with_validation_errors-errors-2). +errors[]+
<ruby>
class Person < ActiveRecord::Base
- validates_presence_of :name
+ validates :name, :presence => true
validates_length_of :name, :minimum => 3
end
@@ -699,7 +699,7 @@ The +clear+ method is used when you intentionally want to clear all the messages
<ruby>
class Person < ActiveRecord::Base
- validates_presence_of :name
+ validates :name, :presence => true
validates_length_of :name, :minimum => 3
end
@@ -723,7 +723,7 @@ The +size+ method returns the total number of error messages for the object.
<ruby>
class Person < ActiveRecord::Base
- validates_presence_of :name
+ validates :name, :presence => true
validates_length_of :name, :minimum => 3
validates_presence_of :email
end