"undefined method `type' for number: string" error when upgrade to Rails4.2


#1

Hi all,

I’m upgrading Rails from 4.1 to 4.2, and I run into an error saying
“undefined method `type’ for “NUMBER(38)”:String”

I did some research but didn’t find any solution except this one:
https://www.ruby-forum.com/topic/6873169

I’m still new to ruby and rails, could you give some advise on how to
resolve this?

Thank you very much.

Here’s the model

class Item < CSRecordBase
has_many :Item_feature_values,
:foreign_key => :item_id
attr_accessible :is_active, :name, :description
self.sequence_name = :item_id_sequence

def self.all_active
    return where("is_active='Y'").order("name")
end

end

Here’s the controller

class WorkCategoriesController < CSApplicationController
def index
@items = Item.all
respond_to do |format|
format.html # index.html.erb
end
end

def show
@item = Item.find(params[:id])
respond_to do |format|
format.html # show.html.erb
end
end

end

Hers’s the view

Listing items

<% @items.each do |item| %>

Item id Name Description
<%=h item.work_category_id %> <%=h item.name %> <%=h item.description %> <%= link_to 'Show', item %> <%= link_to 'Edit', edit_item_path(item) %> <%= link_to 'Destroy', item, data: { confirm: 'Are you sure?' }, :method => :delete %>

#2

Ben Toogood wrote in post #1184912:

Hey Alex,

Your issue is down to STI. The type field is reserved in Rails models to
determine which inheritance class to use.

It seems like you are using type as an integer and not a string. Try
renaming that column and it should fix your problem :slight_smile:

Ben

Hi Ben,

Thank you so much for your reply.
Can you specify how should I rename the column name?

Thanks,
Alex


#3

Hey Alex,

Your issue is down to STI. The type field is reserved in Rails models to
determine which inheritance class to use.

It seems like you are using type as an integer and not a string. Try
renaming that column and it should fix your problem :slight_smile:

Ben


#4

Hi all,

I finally figured that out.
This issue is caused by activerecord-oracle_enhanced-adapter, Rails 4.2
is only compatible with the 1.6 branch of this package.
Please refer to:
https://github.com/rsim/oracle-enhanced/issues/555
https://github.com/rsim/oracle-enhanced/tree/release16

Thank you all,
Alex