Rafa_F
August 30, 2016, 1:28am
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 %>
squeegy
September 6, 2016, 4:37am
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
Ben
Hi Ben,
Thank you so much for your reply.
Can you specify how should I rename the column name?
Thanks,
Alex
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
squeegy
September 9, 2016, 11:20pm
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:
opened 05:26PM - 18 Feb 15 UTC
closed 12:57PM - 25 Feb 15 UTC
I am using the activerecord-oracle_enhanced-adapter 1.5.5 gem built from the rai… ls42 branch. I cloned the Git repository, checked out the rails42 branch, and built the gem. Bundle shows that I am pointing to the correct gem as well so I don't think the issue is on my end. When I run a Rails migration, this is the output:
```
> bin/rake db:migrate RAILS_ENV=development
rake aborted!
NoMethodError: undefined method `type' for "VARCHAR2(255)":String
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/attribute_methods/time_zone_conversion.rb:60:in `create_time_zone_conversion_attribute?'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/attribute_methods/time_zone_conversion.rb:49:in `block (2 levels) in inherited'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/attribute_decorators.rb:61:in `call'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/attribute_decorators.rb:61:in `block in matching'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/attribute_decorators.rb:60:in `select'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/attribute_decorators.rb:60:in `matching'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/attribute_decorators.rb:56:in `decorators_for'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/attribute_decorators.rb:47:in `apply'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/attribute_decorators.rb:29:in `block in add_user_provided_columns'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/attribute_decorators.rb:28:in `map'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/attribute_decorators.rb:28:in `add_user_provided_columns'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/attributes.rb:91:in `columns'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/attributes.rb:96:in `columns_hash'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/querying.rb:41:in `find_by_sql'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/relation.rb:638:in `exec_queries'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/relation.rb:514:in `load'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/relation.rb:243:in `to_a'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/relation/delegation.rb:46:in `map'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:844:in `get_all_versions'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:985:in `migrated'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:990:in `ran?'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:967:in `block in runnable'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:967:in `reject'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:967:in `runnable'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:952:in `migrate'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:820:in `up'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:798:in `migrate'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/apps/free/ruby/gems-1501-2.2.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
/apps/free/ruby/gems-1501-2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
/apps/free/ruby/gems-1501-2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `block in load'
/apps/free/ruby/gems-1501-2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
/apps/free/ruby/gems-1501-2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
-e:1:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
```
Thank you all,
Alex