From 83d4ce6a25efff9ae803a08a9895531aaecacd3c Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 7 Apr 2012 16:58:32 +0530 Subject: Revert "Documents that ActiveRecord instances also support []/[]= methods for reading/writing attributes" This reverts commit a49fe6ec2cb9f22a3b18d7db5ae2ee90325e9d09. Reason: The existing doc about using self[:attribute] is clear enough. --- activerecord/lib/active_record/base.rb | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index d9ea48f7dd..d25a821688 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -114,29 +114,23 @@ module ActiveRecord #:nodoc: # Student.joins(:schools).where(:schools => { :category => 'public' }) # Student.joins(:schools).where('schools.category' => 'public' ) # - # == Dynamic assignment - # - # Sometimes it can be useful to assign some attributes dynamically. You can use - # read_attribute(attr_name, value)/write_attribute(attr_name) - # or through model[attr_name]/model[attr_name]=: - # - # [:deleted, :disabled].each{|p| model[p] = params[p] == 'true' } - # # == Overwriting default accessors # # All column values are automatically available through basic accessors on the Active Record # object, but sometimes you want to specialize this behavior. This can be done by overwriting - # the default accessors (using the same name as the attribute): + # the default accessors (using the same name as the attribute) and calling + # read_attribute(attr_name) and write_attribute(attr_name, value) to actually + # change things. # # class Song < ActiveRecord::Base # # Uses an integer of seconds to hold the length of the song # # def length=(minutes) - # write_attribute(:length, minutes.to_i * 60) # or: self[:length] = minutes.to_i * 60 + # write_attribute(:length, minutes.to_i * 60) # end # # def length - # read_attribute(:length) / 60 # or: self[:length] / 60 + # read_attribute(:length) / 60 # end # end # -- cgit v1.2.3