Skip to content
This repository has been archived by the owner on Jan 8, 2019. It is now read-only.

matthewtodd/default_association_attributes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Because sometimes you just want to say @subscriber.invitations.build

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages