Created
September 10, 2009 18:33
-
-
Save mdeering/184720 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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