Skip to content

Instantly share code, notes, and snippets.

@mdeering
Created September 10, 2009 18:33
Show Gist options
  • Save mdeering/184720 to your computer and use it in GitHub Desktop.
Save mdeering/184720 to your computer and use it in GitHub Desktop.
# I'm trying to setup some attributes on a newly created page instance
# that was created through a association
# page = Page.first
# page.site # => 'mysite'
# new_page = page.children.create
# new_page.site # => 'mysite'
class Page < ActiveRecord::Base
has_many :children, :class_name => 'Page', :foreign_key => :parent_id do
def create(*args)
returning super do |new_page|
# proxy_owner is what I was looking for
new_page.site = proxy_owner.site
end
end
end
end
# Is this the right aproach?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment