Skip to content
This repository
Browse code

Add a clearer example for with_options (lifted from the Active Suppor…

…t guide).
  • Loading branch information...
commit b3e5e25829451acf28c64886b6d9117d2430f7be 1 parent 8af066b
Ben Orenstein r00k authored
24 activesupport/lib/active_support/core_ext/object/with_options.rb
@@ -7,13 +7,27 @@ class Object
7 7 # provided. Each method called on the block variable must take an options
8 8 # hash as its final argument.
9 9 #
10   - # with_options :order => 'created_at', :class_name => 'Comment' do |post|
11   - # post.has_many :comments, :conditions => ['approved = ?', true], :dependent => :delete_all
12   - # post.has_many :unapproved_comments, :conditions => ['approved = ?', false]
13   - # post.has_many :all_comments
  10 + # Without with_options, this code contains duplication:
  11 + #
  12 + # class Account < ActiveRecord::Base
  13 + # has_many :customers, :dependent => :destroy
  14 + # has_many :products, :dependent => :destroy
  15 + # has_many :invoices, :dependent => :destroy
  16 + # has_many :expenses, :dependent => :destroy
  17 + # end
  18 + #
  19 + # Using with_options, we can remove the duplication:
  20 + #
  21 + # class Account < ActiveRecord::Base
  22 + # with_options :dependent => :destroy do |assoc|
  23 + # assoc.has_many :customers
  24 + # assoc.has_many :products
  25 + # assoc.has_many :invoices
  26 + # assoc.has_many :expenses
  27 + # end
14 28 # end
15 29 #
16   - # Can also be used with an explicit receiver:
  30 + # It also be used with an explicit receiver:
17 31 #
18 32 # map.with_options :controller => "people" do |people|
19 33 # people.connect "/people", :action => "index"

0 comments on commit b3e5e25

Please sign in to comment.
Something went wrong with that request. Please try again.