Commit Graph

774 Commits

Author SHA1 Message Date
Francesco Rodriguez
629bc03bf8 change param name to improve documentation
The keys of the error messages are actually attribute names. It makes
the documentation easier to understand:

    # Returns +true+ if the error messages include an error for the given
    # +attribute+, +false+ otherwise.
    #
    #   person.errors.messages # => { :name => ["can not be nil"] }
    #   person.errors.include?(:name) # => true
    #   person.errors.include?(:age)  # => false
    def include?(attribute)
      (v = messages[attribute]) && v.any?
    end
2012-06-22 12:42:32 -05:00
Vijay Dev
35ee8fa3d8 Merge branch 'master' of github.com:lifo/docrails 2012-06-22 22:15:27 +05:30
Vijay Dev
6285675db1 fixes a few mistakes in api docs [ci skip] 2012-06-22 22:14:29 +05:30
Rafael Mendonça França
fb8cf55868 Merge pull request #6800 from mschneider/dynamic_finders_for_aliased_attributes
Dynamic finders for aliased attributes
2012-06-22 07:51:11 -07:00
Maximilian Schneider
f984b8152f made dynamic finders alias_attribute aware
previously dynamic finders only worked in combination with the actual
column name and not its alias defined with #alias_attribute
2012-06-22 16:44:01 +02:00
Francesco Rodriguez
d569bfed0d update ActiveModel::Callbacks documentation [ci skip] 2012-06-22 00:32:54 -05:00
Francesco Rodriguez
c3025e8d59 add description to ActiveModel::MissingAttributeError [ci skip] 2012-06-21 16:56:40 -05:00
Francesco Rodriguez
1ce803d091 add :nodoc: to AM::AttributeMethods#instance_method_already_implemented? [ci skip] 2012-06-21 16:40:17 -05:00
Francesco Rodriguez
95a938a5e6 add example to ActiveModel::AttributeMethods#undefine_attribute_methods [ci skip] 2012-06-21 16:19:40 -05:00
Francesco Rodriguez
f975c4b641 add docs to AM::AttributeMethods#define_attribute_method [ci skip] 2012-06-21 15:51:37 -05:00
Francesco Rodriguez
1cb2cb8bea add :nodoc: to AM::AttributeMethods::AttributeMethodMatcher [ci skip] 2012-06-21 15:37:09 -05:00
Francesco Rodriguez
b5b350ad5c fix ActiveModel::AttributeMethods#alias_attribute documentation [ci skip] 2012-06-21 12:51:39 -05:00
Francesco Rodriguez
bf3332bfdf update ActiveModel::AttributeMethods documentation [ci skip] 2012-06-21 12:26:14 -05:00
Jon Leighton
e030f26ad3 Simplify AR configuration code.
Get rid of ActiveModel::Configuration, make better use of
ActiveSupport::Concern + class_attribute, etc.
2012-06-15 19:15:36 +01:00
Francesco Rodriguez
62f6277c53 add example to ActiveModel::Validations#validators [ci skip] 2012-06-15 11:38:07 -05:00
Vijay Dev
c1474ff2e7 Merge branch 'master' of github.com:lifo/docrails 2012-06-14 22:52:38 +05:30
MrBrdo
bc7c0b5c10 prevent users from unknowingly using bad regexps that can compromise security (http://homakov.blogspot.co.uk/2012/05/saferweb-injects-in-various-ruby.html) 2012-06-14 18:10:49 +02:00
Akira Matsuda
588bb6b987 Range#cover? is not implemented in AS now 2012-06-12 02:29:21 +09:00
Robb Kidd
f20208842a Make observer enable/disable documentation more informative.
* Moved the simplest case--enable/disable all on all--to the top.
* Made clear what "ORM" means to avoid having to teach people how to solve "uninitialized constant ORM"
  errors in their test reports.
2012-06-09 16:04:01 -03:00
Piotr Sarnacki
41d63710f2 Merge pull request #6668 from pomnikita/master
Compact array of values added to PermissionSet instance
2012-06-08 11:35:13 -07:00
Nikita Pomyashchiy
00ff0a6776 Compact array of values added to PermissionSet instance 2012-06-08 01:00:34 +04:00
Francesco Rodriguez
ab11a2780f change AMS::JSON.include_root_in_json default value to false
Changes:

* Update `include_root_in_json` default value to false for default value
  to false for `ActiveModel::Serializers::JSON`.
* Remove unnecessary change to include_root_in_json option in
  wrap_parameters template.
* Update `as_json` documentation.
* Fix JSONSerialization tests.

Problem:

It's confusing that AM serializers behave differently from AR,
even when AR objects include AM serializers module.

    class User < ActiveRecord::Base; end

    class Person
      include ActiveModel::Model
      include ActiveModel::AttributeMethods
      include ActiveModel::Serializers::JSON

      attr_accessor :name, :age

      def attributes
        instance_values
      end
    end

    user.as_json
    => {"id"=>1, "name"=>"Konata Izumi", "age"=>16, "awesome"=>true}
    # root is not included

    person.as_json
    => {"person"=>{"name"=>"Francesco", "age"=>22}}
    # root is included

    ActiveRecord::Base.include_root_in_json
    => false

    Person.include_root_in_json
    => true

    # different default values for include_root_in_json

Proposal:

Change the default value of AM serializers to false, update
the misleading documentation and remove unnecessary change
to false of include_root_in_json option with AR objects.

    class User < ActiveRecord::Base; end

    class Person
      include ActiveModel::Model
      include ActiveModel::AttributeMethods
      include ActiveModel::Serializers::JSON

      attr_accessor :name, :age

      def attributes
        instance_values
      end
    end

    user.as_json
    => {"id"=>1, "name"=>"Konata Izumi", "age"=>16, "awesome"=>true}
    # root is not included

    person.as_json
    => {"name"=>"Francesco", "age"=>22}
    # root is not included

    ActiveRecord::Base.include_root_in_json
    => false

    Person.include_root_in_json
    => false

    # same behaviour, more consistent

Fixes #6578.
2012-06-06 01:11:39 -05:00
Francesco Rodriguez
f87820d00a update ActiveModel::Dirty documentation 2012-05-31 05:06:00 -05:00
José Valim
555d8152c7 Merge pull request #5843 from kuroda/translation_of_deeply_nested_model_attributes
Fix human attribute_name to handle deeply nested attributes
2012-05-29 23:26:26 -07:00
Steve Purcell
b3ccd7b27a Don't enable validations when passing false hash values to ActiveModel.validates
Passing a falsey option value for a validator currently causes that validator to
be enabled, just like "true":

    ActiveModel.validates :foo, :presence => false

This is rather counterintuitive, and makes it inconvenient to wrap `validates` in
methods which may conditionally enable different validators.

As an example, one is currently forced to write:

      def has_slug(source_field, options={:unique => true})
        slugger = Proc.new { |r| r[:slug] = self.class.sluggify(r[source_field]) if r[:slug].blank? }
        before_validation slugger
        validations = { :presence => true, :slug => true }
        if options[:unique]
          validations[:uniqueness] = true
        end
        validates :slug, validations
      end

because the following reasonable-looking alternative fails to work as expected:

      def has_slug(source_field, options={:unique => true})
        slugger = Proc.new { |r| r[:slug] = self.class.sluggify(r[source_field]) if r[:slug].blank? }
        before_validation slugger
        validates :slug, :presence => true, :slug => true, :uniqueness => options[:unique]
      end

(This commit includes a test, and all activemodel and activerecord tests pass as before.)
2012-05-28 15:02:02 +01:00
Vijay Dev
575e77ba16 Merge branch 'master' of github.com:lifo/docrails 2012-05-26 17:49:59 +05:30
Edward Tsech
b98a343da5 Add comment for attr_accessible/attr_protected :as option. [ci skip] 2012-05-25 16:35:53 +02:00
José Valim
56417b4092 Merge pull request #4785 from ayamomiji/add-self-to-allow-method-name-using-ruby-keyword
add `self.` to allow method name using ruby keyword
2012-05-25 00:29:07 -07:00
Angelo capilleri
5646d65d01 changed xml type datetime to dateTime, fixes #6328
XmlMini define the xml 'datatime', but according to
http://www.w3.org/TR/xmlschema-2/#dateTime could be better
change this to 'dateTime' with upper case letter 'T.
So 'DateTime' and 'Time' are redefined from 'datetime' to 'dateTime'

add the changing to the changelog
2012-05-23 14:45:56 +02:00
Piotr Sarnacki
08a5b10eb1 Revert "Merge pull request #5702 from oscardelben/patch-4"
This reverts commit cae1ca7d1be9c79c7ef012a1f62aef9d3bb815f8, reversing
changes made to da97cf016a8ffd1f54f804cd881f393e5d6efc18.

These changes break the build, it needs more investigation.
2012-05-20 11:11:20 -07:00
Piotr Sarnacki
cae1ca7d1b Merge pull request #5702 from oscardelben/patch-4
Call undefine_attribute_methods only when defining new attributes
2012-05-19 23:57:58 -07:00
Carlos Antonio da Silva
f20032fa15 Merge pull request #5678 from troyk/patch-1
Remove sort on attributes.keys
2012-05-19 06:08:33 -07:00
Oscar Del Ben
42d0b1c8dd Call undefine_attribute_methods only when defining new attributes 2012-05-18 08:50:57 -07:00
Aaron Patterson
1b604c73f1 Merge pull request #6215 from erichmenge/fix_has_secure_password
Fix has secure password
2012-05-17 10:32:15 -07:00
Vijay Dev
03f8a57487 Merge branch 'master' of github.com:lifo/docrails
Conflicts:
	activerecord/lib/active_record/core.rb
2012-05-17 17:49:33 +05:30
Naoto Takai
80a2c9e5db Improve logging of ActiveModel::MassAssignmentSecurity::Sanitizer 2012-05-17 06:55:41 +09:00
Francesco Rodriguez
3004bc2470 fixing removed empty lines and examples 2012-05-16 10:01:43 -05:00
Francesco Rodriguez
a9e66c62e9 fixing validates_with docs 2012-05-16 08:56:31 -05:00
Francesco Rodriguez
95e14d1523 better format and fixes to validators docs 2012-05-16 01:23:46 -05:00
Francesco Rodriguez
007c3d8bcb better example format in validates_exclusion_of docs 2012-05-16 00:06:44 -05:00
Tsutomu Kuroda
b0e2fc843b Fix human attribute_name to handle deeply nested attributes
When a model nests another model that also nests yet another model
using accepts_nested_attributes_for method, its Errors object can
have an attribute name with "contacts.addresses.street" style.

In this case, the dots within the namespace should be substituted
with slashes so that we can provide the translation under the
"activemodel.attributes.person/contacts/addresses.street" key.

This commit is related to #3859.
2012-05-16 08:39:48 +09:00
Carlos Antonio da Silva
9b4f5041d2 Kill whitespaces ✂️ 2012-05-15 13:38:29 -03:00
Carlos Antonio da Silva
3d1b078a5b Merge pull request #6284 from acapilleri/dup_validation
clean the erros if an object that includes validation  is duped.
2012-05-15 05:20:57 -07:00
Vijay Dev
59b03d418f Merge branch 'master' of github.com:lifo/docrails
Conflicts:
	actionpack/lib/action_view/helpers/asset_tag_helper.rb
2012-05-15 13:13:55 +05:30
Francesco Rodriguez
00c94d7d94 updating define_attribute_methods documentation 2012-05-14 11:38:23 -05:00
Francesco Rodriguez
05234b358f allow define_attribute_methods to pass multiple values 2012-05-14 11:35:15 -05:00
Alexey Vakhov
7a95d079a3 Missed colon 2012-05-14 09:13:59 +04:00
Angelo Capilleri
f9ae1baa0a clean the erros if an object that includes validations errors is duped. Fixes #5953 2012-05-13 23:24:05 +02:00
ayaya
c140a27fc5 fix alias_attribute will raise a syntax error if make an alias on a
column that named as a ruby keyword
2012-05-14 00:57:29 +08:00
José Valim
7d67880a2d Merge pull request #5729 from oscardelben/use_tap
Use the more idiomatic tap method
2012-05-13 01:00:17 -07:00