Created
April 18, 2011 20:19
-
-
Save patricksrobertson/926074 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
# app/models/post.rb | |
class Post < ActiveRecord::Base | |
has_one :comment | |
def name | |
"I'm overriding a delegated method!" | |
end | |
end | |
# app/models/comment.rb | |
class Comments < ActiveRecord::Base | |
belongs_to :post | |
delegate :name, :to => :post | |
end | |
############################################ | |
@post = Post.create! | |
comment = @post.comment.build(:name => "Waffles") | |
@post.name | |
>> "I'm overriding a delegated method!" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment