Skip to content

Instantly share code, notes, and snippets.

@agibralter
Created January 6, 2009 04:45
Show Gist options
  • Save agibralter/43673 to your computer and use it in GitHub Desktop.
Save agibralter/43673 to your computer and use it in GitHub Desktop.
class Post < ActiveRecord::Base
has_many :comments
attr_accessor :current_comment
end
class Comment < ActiveRecord::Base
module Foo
def and_set_current_comment
self.current_comment = proxy_owner
self
end
end
belongs_to :post, :extend => Foo
end
# in code, lets say post 12 has 10 comments
@post = Post.find(12)
@comment = @post.comments.first
@post = @comment.post.and_set_current_comment
@post.current_comment = @comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment