diff options
author | Ben Orenstein <ben.orenstein@gmail.com> | 2011-02-19 12:15:51 -0500 |
---|---|---|
committer | Ben Orenstein <ben.orenstein@gmail.com> | 2011-02-19 12:15:51 -0500 |
commit | b3e5e25829451acf28c64886b6d9117d2430f7be (patch) | |
tree | 299f296ac024016397e03a3b89008cad900c2d0c /activesupport/lib/active_support/core_ext | |
parent | 8af066b1666b63caab31126273fc757abe724906 (diff) | |
download | rails-b3e5e25829451acf28c64886b6d9117d2430f7be.tar.gz rails-b3e5e25829451acf28c64886b6d9117d2430f7be.tar.bz2 rails-b3e5e25829451acf28c64886b6d9117d2430f7be.zip |
Add a clearer example for with_options (lifted from the Active Support guide).
Diffstat (limited to 'activesupport/lib/active_support/core_ext')
-rw-r--r-- | activesupport/lib/active_support/core_ext/object/with_options.rb | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/core_ext/object/with_options.rb b/activesupport/lib/active_support/core_ext/object/with_options.rb index 3209cf7f11..33aeeb2391 100644 --- a/activesupport/lib/active_support/core_ext/object/with_options.rb +++ b/activesupport/lib/active_support/core_ext/object/with_options.rb @@ -7,13 +7,27 @@ class Object # provided. Each method called on the block variable must take an options # hash as its final argument. # - # with_options :order => 'created_at', :class_name => 'Comment' do |post| - # post.has_many :comments, :conditions => ['approved = ?', true], :dependent => :delete_all - # post.has_many :unapproved_comments, :conditions => ['approved = ?', false] - # post.has_many :all_comments + # Without with_options, this code contains duplication: + # + # class Account < ActiveRecord::Base + # has_many :customers, :dependent => :destroy + # has_many :products, :dependent => :destroy + # has_many :invoices, :dependent => :destroy + # has_many :expenses, :dependent => :destroy + # end + # + # Using with_options, we can remove the duplication: + # + # class Account < ActiveRecord::Base + # with_options :dependent => :destroy do |assoc| + # assoc.has_many :customers + # assoc.has_many :products + # assoc.has_many :invoices + # assoc.has_many :expenses + # end # end # - # Can also be used with an explicit receiver: + # It also be used with an explicit receiver: # # map.with_options :controller => "people" do |people| # people.connect "/people", :action => "index" |