Skip to content

Instantly share code, notes, and snippets.

@sheldonbaker
Created April 8, 2011 11:35
Show Gist options
  • Save sheldonbaker/909677 to your computer and use it in GitHub Desktop.
Save sheldonbaker/909677 to your computer and use it in GitHub Desktop.
class Video < ActiveRecord::Base
inherits_from :item
end
class Article < ActiveRecord::Base
inherits_from :item
end
class Item < ActiveRecord::Base
has_many :responses
end
class Response < ActiveRecord::Base
belongs_to :item
validates_presence_of :item_id
end
# in console:
#
# saving a new video item (maybe at items/video/new)
v = Video.new
v.save # true
# saving a response to that (video) item
r = Response.new
r.item = Item.find(1) #causes error
# error:
#
# ActiveRecord::AssociationTypeMismatch: Item(#2157741480) expected, got Video(#2155124540)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment