diff options
author | Jon Moss <me@jonathanmoss.me> | 2017-03-12 11:25:24 -0400 |
---|---|---|
committer | Jon Moss <me@jonathanmoss.me> | 2017-03-12 11:25:54 -0400 |
commit | 8f9241b076c836a318649f26e7677ae1390c3b9a (patch) | |
tree | f88b3254a6d2e399c14f9999bc539c20b6258723 | |
parent | 4d5060072b5446e0d13873f7edbecaf3527e7846 (diff) | |
download | rails-8f9241b076c836a318649f26e7677ae1390c3b9a.tar.gz rails-8f9241b076c836a318649f26e7677ae1390c3b9a.tar.bz2 rails-8f9241b076c836a318649f26e7677ae1390c3b9a.zip |
First editing pass on "Active Model Basics" guide
Lots of grammar, etc fixes.
[ci skip]
-rw-r--r-- | guides/source/active_model_basics.md | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/guides/source/active_model_basics.md b/guides/source/active_model_basics.md index 72daa29f7f..a35d0e4067 100644 --- a/guides/source/active_model_basics.md +++ b/guides/source/active_model_basics.md @@ -87,7 +87,7 @@ end ### Conversion If a class defines `persisted?` and `id` methods, then you can include the -`ActiveModel::Conversion` module in that class and call the Rails conversion +`ActiveModel::Conversion` module in that class, and call the Rails conversion methods on objects of that class. ```ruby @@ -132,7 +132,7 @@ class Person end def last_name - @last_name + @last_nameperson.changes # => {"first_name"=>[nil, "First Name"]} end def last_name=(value) @@ -156,16 +156,17 @@ person.changed? # => false person.first_name = "First Name" person.first_name # => "First Name" -# returns true if any of the attributes have unsaved changes, false otherwise. +# returns true if any of the attributes have unsaved changes. person.changed? # => true # returns a list of attributes that have changed before saving. person.changed # => ["first_name"] -# returns a hash of the attributes that have changed with their original values. +# returns a Hash of the attributes that have changed with their original values. person.changed_attributes # => {"first_name"=>nil} -# returns a hash of changes, with the attribute names as the keys, and the values will be an array of the old and new value for that field. +# returns a Hash of changes, with the attribute names as the keys, and the +# values as an array of the old and new values for that field. person.changes # => {"first_name"=>[nil, "First Name"]} ``` @@ -179,7 +180,7 @@ person.first_name # => "First Name" person.first_name_changed? # => true ``` -Track what was the previous value of the attribute. +Track the previous value of the attribute. ```ruby # attr_name_was accessor @@ -187,7 +188,7 @@ person.first_name_was # => nil ``` Track both previous and current value of the changed attribute. Returns an array -if changed, else returns nil. +if changed, otherwise returns nil. ```ruby # attr_name_change @@ -197,7 +198,7 @@ person.last_name_change # => nil ### Validations -The `ActiveModel::Validations` module adds the ability to validate class objects +The `ActiveModel::Validations` module adds the ability to validate objects like in Active Record. ```ruby @@ -225,7 +226,7 @@ person.valid? # => raises ActiveModel::StrictValidationFa ### Naming -`ActiveModel::Naming` adds a number of class methods which make the naming and routing +`ActiveModel::Naming` adds a number of class methods which make naming and routing easier to manage. The module defines the `model_name` class method which will define a number of accessors using some `ActiveSupport::Inflector` methods. @@ -248,7 +249,7 @@ Person.model_name.singular_route_key # => "person" ### Model -`ActiveModel::Model` adds the ability to a class to work with Action Pack and +`ActiveModel::Model` adds the ability for a class to work with Action Pack and Action View right out of the box. ```ruby @@ -308,7 +309,7 @@ class Person end ``` -Now you can access a serialized hash of your object using the `serializable_hash`. +Now you can access a serialized hash of your object using the `serializable_hash` method. ```ruby person = Person.new |