github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

matthewtodd / default_association_attributes

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 2
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (1)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (1)
    • 0.1.0
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

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

  cancel

http://matthewtodd.org/2009/03/02/default-association-attributes-in-active_record.html

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Bundle the Rakefile, too. 
matthewtodd (author)
Mon Mar 02 04:51:49 -0800 2009
commit  8e19050d90e858868a65b83bbe5350086bbec2bc
tree    c0c97922b88852b7829abab928d5b053de2eca5c
parent  ab1f869cf6a2c9988e9e83e036e3095a43f9689f
default_association_attributes /
name age
history
message
file .gitignore Loading commit data...
file MIT-LICENSE
file README.rdoc
file Rakefile
file default_association_attributes.gemspec
directory lib/
directory test/
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

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server