aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorVijay Dev <vijaydev.cse@gmail.com>2012-05-08 23:56:25 +0530
committerVijay Dev <vijaydev.cse@gmail.com>2012-05-08 23:56:25 +0530
commit7918d7bf5c6f0ce53e648c793f6034d6216a4808 (patch)
treefebc17be0b2768394b67a14fa7dee842d3bde3b6 /activemodel
parent882e750cbe09450388190e92e2d92eac352b40fa (diff)
parent7e26f7f0f7e3c230c333e1b265727a9b8cf7c91f (diff)
downloadrails-7918d7bf5c6f0ce53e648c793f6034d6216a4808.tar.gz
rails-7918d7bf5c6f0ce53e648c793f6034d6216a4808.tar.bz2
rails-7918d7bf5c6f0ce53e648c793f6034d6216a4808.zip
Merge branch 'master' of github.com:lifo/docrails
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/README.rdoc10
-rw-r--r--activemodel/lib/active_model/attribute_methods.rb12
2 files changed, 22 insertions, 0 deletions
diff --git a/activemodel/README.rdoc b/activemodel/README.rdoc
index 1fd75141f8..0c7089598c 100644
--- a/activemodel/README.rdoc
+++ b/activemodel/README.rdoc
@@ -135,6 +135,16 @@ behavior out of the box:
pattern in a Rails App and take advantage of all the standard observer
functions.
+ class PersonObserver < ActiveModel::Observer
+ def after_create(person)
+ person.logger.info("New person added!")
+ end
+
+ def after_destroy(person)
+ person.logger.warn("Person with an id of #{person.id} was destroyed!")
+ end
+ end
+
{Learn more}[link:classes/ActiveModel/Observer.html]
* Making objects serializable
diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb
index 97a83e58af..25d5d84ce6 100644
--- a/activemodel/lib/active_model/attribute_methods.rb
+++ b/activemodel/lib/active_model/attribute_methods.rb
@@ -180,6 +180,18 @@ module ActiveModel
undefine_attribute_methods
end
+
+ # Allows you to make aliases for attributes.
+ #
+ # class Person
+ # attr_accessor :name
+ # alias_attribute :nickname, :name
+ # end
+ #
+ # person = Person.new
+ # person.nickname = "Bob"
+ # person.nickname # => "Bob"
+ # person.name # => "Bob"
def alias_attribute(new_name, old_name)
attribute_method_matchers.each do |matcher|
matcher_new = matcher.method_name(new_name).to_s