aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-08-25 07:10:16 -0700
committerJosé Valim <jose.valim@gmail.com>2011-08-25 07:10:16 -0700
commitd15069316f331c46165248c2df869145fef60008 (patch)
treeb3565673bfd275620a41b50b1fbe86b4d798c4e3 /railties
parent68424fb1cf45acda3ad1daef30136f3bcd4f9f9d (diff)
parentcbb147931b2f547ad76a7ed233430642490c6000 (diff)
downloadrails-d15069316f331c46165248c2df869145fef60008.tar.gz
rails-d15069316f331c46165248c2df869145fef60008.tar.bz2
rails-d15069316f331c46165248c2df869145fef60008.zip
Merge pull request #2563 from bogdan/internal_validation
Implemented strict validation concept
Diffstat (limited to 'railties')
-rw-r--r--railties/guides/source/active_model_basics.textile7
-rw-r--r--railties/guides/source/active_record_validations_callbacks.textile1
2 files changed, 6 insertions, 2 deletions
diff --git a/railties/guides/source/active_model_basics.textile b/railties/guides/source/active_model_basics.textile
index 3c19fb5177..ec27a071c9 100644
--- a/railties/guides/source/active_model_basics.textile
+++ b/railties/guides/source/active_model_basics.textile
@@ -183,20 +183,23 @@ Validations module adds the ability to class objects to validate them in Active
class Person
include ActiveModel::Validations
- attr_accessor :name, :email
+ attr_accessor :name, :email, :token
validates :name, :presence => true
validates_format_of :email, :with => /^([^\s]+)((?:[-a-z0-9]\.)[a-z]{2,})$/i
+ validates! :token, :presence => true
end
-person = Person.new
+person = Person.new(:token => "2b1f325")
person.valid? #=> false
person.name = 'vishnu'
person.email = 'me'
person.valid? #=> false
person.email = 'me@vishnuatrai.com'
person.valid? #=> true
+person.token = nil
+person.valid? #=> raises ActiveModel::StrictValidationFailed
</ruby>
h3. Changelog
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile
index aba3224ba7..18fc77c660 100644
--- a/railties/guides/source/active_record_validations_callbacks.textile
+++ b/railties/guides/source/active_record_validations_callbacks.textile
@@ -1270,6 +1270,7 @@ The +after_commit+ and +after_rollback+ callbacks are guaranteed to be called fo
h3. Changelog
+* August 24, 2011: Add strict validation usage example. "Bogdan Gusiev":http://gusiev.com
* February 17, 2011: Add description of transaction callbacks.
* July 20, 2010: Fixed typos and rephrased some paragraphs for clarity. "Jaime Iniesta":http://jaimeiniesta.com
* May 24, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com