From b2ccae466e12659df97969661dae389ac0eb6e2c Mon Sep 17 00:00:00 2001 From: Oscar Del Ben Date: Thu, 26 Apr 2012 09:35:26 +0200 Subject: Enhance validations documentation --- activemodel/lib/active_model/validations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activemodel/lib/active_model') diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb index 0e15155b85..ebb0dbb1ca 100644 --- a/activemodel/lib/active_model/validations.rb +++ b/activemodel/lib/active_model/validations.rb @@ -65,7 +65,7 @@ module ActiveModel # # attr_accessor :first_name, :last_name # - # validates_each :first_name, :last_name do |record, attr, value| + # validates_each :first_name, :last_name, :allow_blank => true do |record, attr, value| # record.errors.add attr, 'starts with z.' if value.to_s[0] == ?z # end # end -- cgit v1.2.3 From 26353b993b3bfb52d6c4adb92b6aa08d9712fd06 Mon Sep 17 00:00:00 2001 From: Oscar Del Ben Date: Thu, 26 Apr 2012 10:09:12 +0200 Subject: Add documentation for validate options --- activemodel/lib/active_model/validations.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'activemodel/lib/active_model') diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb index ebb0dbb1ca..b5e9d7514a 100644 --- a/activemodel/lib/active_model/validations.rb +++ b/activemodel/lib/active_model/validations.rb @@ -128,6 +128,19 @@ module ActiveModel # end # end # + # Options: + # * :on - Specifies the context where this validation is active + # (e.g. :on => :create or :on => :custom_validation_context) + # * :allow_nil - Skip validation if attribute is +nil+. + # * :allow_blank - Skip validation if attribute is blank. + # * :if - Specifies a method, proc or string to call to determine + # if the validation should occur (e.g. :if => :allow_validation, + # or :if => Proc.new { |user| user.signup_step > 2 }). The method, + # proc or string should return or evaluate to a true or false value. + # * :unless - Specifies a method, proc or string to call to determine if the validation should + # not occur (e.g. :unless => :skip_validation, or + # :unless => Proc.new { |user| user.signup_step <= 2 }). The + # method, proc or string should return or evaluate to a true or false value. def validate(*args, &block) options = args.extract_options! if options.key?(:on) -- cgit v1.2.3 From 8c1633328699cc00b1b8a893bffa6390c2cdfcc0 Mon Sep 17 00:00:00 2001 From: Oscar Del Ben Date: Thu, 26 Apr 2012 10:34:51 +0200 Subject: minor docs improvements --- activemodel/lib/active_model/validations.rb | 2 +- activemodel/lib/active_model/validations/with.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'activemodel/lib/active_model') diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb index b5e9d7514a..3ed72bae3b 100644 --- a/activemodel/lib/active_model/validations.rb +++ b/activemodel/lib/active_model/validations.rb @@ -158,7 +158,7 @@ module ActiveModel _validators.values.flatten.uniq end - # List all validators that being used to validate a specific attribute. + # List all validators that are being used to validate a specific attribute. def validators_on(*attributes) attributes.map do |attribute| _validators[attribute.to_sym] diff --git a/activemodel/lib/active_model/validations/with.rb b/activemodel/lib/active_model/validations/with.rb index 72b8562b93..991c5f7b82 100644 --- a/activemodel/lib/active_model/validations/with.rb +++ b/activemodel/lib/active_model/validations/with.rb @@ -126,12 +126,12 @@ module ActiveModel # end # # Standard configuration options (:on, :if and :unless), which are - # available on the class version of validates_with, should instead be - # placed on the validates method as these are applied and tested + # available on the class version of +validates_with+, should instead be + # placed on the +validates+ method as these are applied and tested # in the callback # # If you pass any additional configuration options, they will be passed - # to the class and available as options, please refer to the + # to the class and available as +options+, please refer to the # class version of this method for more information # def validates_with(*args, &block) -- cgit v1.2.3 From 8cc4159018929fb4b0aa431b7041f6a66f160180 Mon Sep 17 00:00:00 2001 From: Mark Rushakof Date: Fri, 27 Apr 2012 00:00:30 -0700 Subject: Use Foo::Bar instead of +Foo::Bar+ The latter doesn't render as code in HTML output. Regex used in Rubymine to locate the latter form: (\+)(:*\w+:(?::|\w)+)(\+) --- activemodel/lib/active_model/serialization.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activemodel/lib/active_model') diff --git a/activemodel/lib/active_model/serialization.rb b/activemodel/lib/active_model/serialization.rb index a5828476b1..4403ef060b 100644 --- a/activemodel/lib/active_model/serialization.rb +++ b/activemodel/lib/active_model/serialization.rb @@ -34,7 +34,7 @@ module ActiveModel # # Most of the time though, you will want to include the JSON or XML # serializations. Both of these modules automatically include the - # +ActiveModel::Serialization+ module, so there is no need to explicitly + # ActiveModel::Serialization module, so there is no need to explicitly # include it. # # A minimal implementation including XML and JSON would be: -- cgit v1.2.3