public
Description: Because sometimes you just want to say @subscriber.invitations.build
Homepage: http://matthewtodd.org/2009/03/02/default-association-attributes-in-active_record.html
Clone URL: git://github.com/matthewtodd/default_association_attributes.git
matthewtodd (author)
Mon Mar 02 04:51:49 -0800 2009
commit  8e19050d90e858868a65b83bbe5350086bbec2bc
tree    c0c97922b88852b7829abab928d5b053de2eca5c
parent  ab1f869cf6a2c9988e9e83e036e3095a43f9689f
name age message
file .gitignore Mon Mar 02 04:42:35 -0800 2009 Release 0.1.0. [matthewtodd]
file MIT-LICENSE Mon Mar 02 04:42:35 -0800 2009 Release 0.1.0. [matthewtodd]
file README.rdoc Mon Mar 02 04:42:35 -0800 2009 Release 0.1.0. [matthewtodd]
file Rakefile Mon Mar 02 04:51:49 -0800 2009 Bundle the Rakefile, too. [matthewtodd]
file default_association_attributes.gemspec Mon Mar 02 04:42:35 -0800 2009 Release 0.1.0. [matthewtodd]
directory lib/ Mon Mar 02 04:42:35 -0800 2009 Release 0.1.0. [matthewtodd]
directory test/ Mon Mar 02 04:42:35 -0800 2009 Release 0.1.0. [matthewtodd]
README.rdoc

DefaultAssociationAttributes

Because sometimes all you want to say is

 @subscriber.invitations.build

For more motivation, see the blog post, matthewtodd.org/2009/03/02/default-association-attributes-in-active_record.html

Installation

As a gem:

  config.gem 'matthewtodd-default_association_attributes', :lib => 'default_association_attributes', :source => 'http://gems.github.com'

As a plugin:

  script/plugin install git://github.com/matthewtodd/default_association_attributes.git

Usage

In your model:

 class Subscriber < ActiveRecord::Base
   has_many :invitations, :extend => DefaultAssociationAttributes do
     def default_attributes
       { :email => proxy_owner.email }
     end
   end
 end

Copyright © 2009 Matthew Todd, released under the MIT license