text 16 Dec Rails STI

I recently started using Single Table Inheritance in a Rails project. It works pretty well for the most part, until you start trying to reference the type attribute in the parent class.

>> o.type
warning: Object#type is deprecated; use Object#class

This will probably cause you all type of madness until you track it down.

You can work around by calling o[‘type’] or o[:type] or just setting up some new methods:

  def class_name_type
    self[:type]
  end

  def class_name_type=(s)
    self[:type] = s
 end
blog comments powered by Disqus

Design inspired by Prashanth Kamalakanthan. Content powered by Tumblr.