Skip to content

Instantly share code, notes, and snippets.

@tbaba
Created September 4, 2011 15:24
Show Gist options
  • Save tbaba/1193011 to your computer and use it in GitHub Desktop.
Save tbaba/1193011 to your computer and use it in GitHub Desktop.
Single Table Inheritance Sample
class CreateArticles < ActiveRecord::Migration
self.up
create_table :articles do |t|
t.string :title
t.text :body
t.string :type
t.timestamps
end
end
self.down
drop_table :articles
end
end
# article.rb
class Article < ActiveRecord::Base
end
# post.rb
class Post < Article
end
# page.rb
class Page < Article
end
---
> Post.all
=> [<Post>, <Post>]
> Page.all
=> [<Page>, <Page>]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment