From f69d5cddf0d05388685b64d42cfa50bbca5b4b80 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Wed, 25 May 2011 22:04:35 +0530 Subject: changes validates_inclusion & exclusion to newer syntax --- .../source/active_record_validations_callbacks.textile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'railties/guides') 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 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 @@ -264,8 +264,8 @@ This helper validates that the attributes' values are included in a given set. I 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 @@ -471,8 +471,8 @@ The +:allow_nil+ option skips the validation when the value being validated is + 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 @@ -598,7 +598,7 @@ You can even create your own validation helpers and reuse them in several differ 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 -- cgit v1.2.3