Skip to content

Instantly share code, notes, and snippets.

@patricksrobertson
Created April 18, 2011 20:19
Show Gist options
  • Save patricksrobertson/926074 to your computer and use it in GitHub Desktop.
Save patricksrobertson/926074 to your computer and use it in GitHub Desktop.
# 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