Skip to content

Instantly share code, notes, and snippets.

@tekin
Created August 26, 2011 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tekin/1173659 to your computer and use it in GitHub Desktop.
Save tekin/1173659 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
has_many :events, :extend => AssociationDefaultAttributes do
def default_attributes
{ :venue => proxy_owner.default_venue }
end
end
end
module AssociationDefaultAttributes
def create(attrs, &block)
super(default_attributes.merge(attrs), &block)
end
def build(attrs={}, &block)
super(default_attributes.merge(attrs), &block)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment