Object#type is deprecated; use Object#class

Thanks in advance for being patient with this rails newbie
When I do the STI example in AWDWR i get a warning: Object#type is
deprecated; use Object#class
What does this mean?
How should I change the following code?

This is from page 342 AWDWR
create_table :people, :force => true do |t|
t.column :type, :string

Can I change this to

t.column :kind, :string with no ill effects? Or is their something
special about a column with the name type?
I read this on http://api.pluginaweek.org/type_attributes/

In Ruby 1.8, type is a deprecated attribute replaced by the class
method. However, since type is also used in class inheritance within
ActiveRecord, it will not allow you to access the type attribute as
defined in a model’s table. Instead, it will return the actual class
using the deprecated method. This bug fix accesses the actual
attribute instead if type is defined as a column in the model’s table.
Should I redefine type as suggested here or is there a better way?

module PluginAWeek #:nodoc:

Allow +type+ to be accessed as a attribute

module TypeAttributes
# Retrieves the current value for +type+
def type
self.class.column_names.include?(‘type’) ?
read_attribute(:type) : super

ActiveRecord::Base.class_eval do
include PluginAWeek::TypeAttributes

Change :type to :person_type. That should solve your problem.

Btw, if you change it to person_type also change the sti id to
person_id. You don’t have to use person, you can use anything you want,
but person seems to fit your schema.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs