Skip to content

Instantly share code, notes, and snippets.

@DCarper
Created February 24, 2011 17:51
Show Gist options
  • Select an option

  • Save DCarper/842541 to your computer and use it in GitHub Desktop.

Select an option

Save DCarper/842541 to your computer and use it in GitHub Desktop.
class Comment < ActiveRecord::Base
belongs_to :commentable, :polymorphic => true
has_one :user, :through => :commentable,
end
#(rdb:1) @comment.valid?
# => true
#(rdb:1) @comment.commentable.valid?
# => true
#(rdb:1) @comment.commentable.user.valid?
# => true
#(rdb:1) @comment.user
# => NameError Exception: uninitialized constant Comment::Commentable
class Membership < ActiveRecord::Base
belongs_to :user
has_many :comments, :as => :commentable
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment