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

D5d1667315b5ce3d53330b6839a5787a?d=identicon&s=25 Alex Wanq (w41q)
on 2016-08-30 01:28
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

<h1>Listing items</h1>
<table>
  <tr>
    <th>Item id</th>
    <th>Name</th>
    <th>Description</th>
  </tr>

<% @items.each do |item| %>
   <tr>
    <td><%=h item.work_category_id %></td>
    <td><%=h item.name %></td>
    <td><%=h item.description %></td>
    <td><%= link_to 'Show', item %></td>
    <td><%= link_to 'Edit', edit_item_path(item) %></td>
    <td><%= link_to 'Destroy', item, data: { confirm: 'Are you sure?' },
:method => :delete %></td>
  </tr>
</table>
B896fce62a47fc4bce2dbd9ed7a26eb2?d=identicon&s=25 Ben Toogood (ben-toogood)
on 2016-08-30 17:33
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 :)

Ben
D5d1667315b5ce3d53330b6839a5787a?d=identicon&s=25 Alex Wanq (w41q)
on 2016-09-06 04:37
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 :)
>
> Ben

Hi Ben,

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

Thanks,
Alex
D5d1667315b5ce3d53330b6839a5787a?d=identicon&s=25 Alex Wanq (w41q)
on 2016-09-09 23:20
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
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.