diff options
author | Vijay Dev <vijaydev.cse@gmail.com> | 2011-05-25 22:04:35 +0530 |
---|---|---|
committer | Vijay Dev <vijaydev.cse@gmail.com> | 2011-05-25 22:17:36 +0530 |
commit | f69d5cddf0d05388685b64d42cfa50bbca5b4b80 (patch) | |
tree | d95ea45a6c838d7cf064fd8014050ac5cf406388 | |
parent | 34a05a701bb72aca2f482c4005af9cd9ea546afe (diff) | |
download | rails-f69d5cddf0d05388685b64d42cfa50bbca5b4b80.tar.gz rails-f69d5cddf0d05388685b64d42cfa50bbca5b4b80.tar.bz2 rails-f69d5cddf0d05388685b64d42cfa50bbca5b4b80.zip |
changes validates_inclusion & exclusion to newer syntax
-rw-r--r-- | railties/guides/source/active_record_validations_callbacks.textile | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index fbafb23417..b6a2a10460 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -236,8 +236,8 @@ This helper validates that the attributes' values are not included in a given se <ruby> class Account < ActiveRecord::Base - validates_exclusion_of :subdomain, :in => %w(www us ca jp), - :message => "Subdomain %{value} is reserved." + validates :subdomain, :exclusion => { :in => %w(www us ca jp), + :message => "Subdomain %{value} is reserved." } end </ruby> @@ -264,8 +264,8 @@ This helper validates that the attributes' values are included in a given set. I <ruby> class Coffee < ActiveRecord::Base - validates_inclusion_of :size, :in => %w(small medium large), - :message => "%{value} is not a valid size" + validates :size, :inclusion => { :in => %w(small medium large), + :message => "%{value} is not a valid size" } end </ruby> @@ -471,8 +471,8 @@ The +:allow_nil+ option skips the validation when the value being validated is + <ruby> class Coffee < ActiveRecord::Base - validates_inclusion_of :size, :in => %w(small medium large), - :message => "%{value} is not a valid size", :allow_nil => true + validates :size, :inclusion => { :in => %w(small medium large), + :message => "%{value} is not a valid size" }, :allow_nil => true end </ruby> @@ -598,7 +598,7 @@ You can even create your own validation helpers and reuse them in several differ <ruby> ActiveRecord::Base.class_eval do def self.validates_as_choice(attr_name, n, options={}) - validates_inclusion_of attr_name, {:in => 1..n}.merge(options) + validates attr_name, :inclusion => { {:in => 1..n}.merge(options) } end end </ruby> |