diff options
author | Ben Orenstein <ben.orenstein@gmail.com> | 2011-02-19 12:15:51 -0500 |
---|---|---|
committer | Mani Tadayon <bowsersenior@gmail.com> | 2011-02-21 13:44:18 -0800 |
commit | 797af0faa54721046fd72974d8241e80fa89e182 (patch) | |
tree | 109f306c6cbde077a3eb044fb8e6f7f85da35781 /activesupport/lib | |
parent | 74b44dfb86365c805a6fe610da3764e00b4f96aa (diff) | |
download | rails-797af0faa54721046fd72974d8241e80fa89e182.tar.gz rails-797af0faa54721046fd72974d8241e80fa89e182.tar.bz2 rails-797af0faa54721046fd72974d8241e80fa89e182.zip |
Add a clearer example for with_options (lifted from the Active Support guide).
Diffstat (limited to 'activesupport/lib')
-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" |