Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: None  |  size: 0.41 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to customize Rails 3 STI column name
  2. class Post < ActiveRecord::Base
  3. end
  4.        
  5. class Question < Post
  6. end
  7.        
  8. class Answer < Post
  9. end
  10.        
  11. class Post < ActiveRecord::Base
  12.   self.inheritance_column = 'type_column_name'
  13.  
  14. end
  15.        
  16. class Post < ActiveRecord::Base
  17.   scope :questions, where(:post_type_id => 0)
  18.   scope :answers, where(:post_type_id => 1)
  19.  
  20. end
  21.  
  22. @questions = Post.questions.all
  23. @answers = Post.answers.all