Адаптер ActiveRecord oracle_enhanced не смог загрузить библиотеку ruby-oci8

rails g scaffold не удалось, но скрипт oci и запрос данных irb работали. Не мог понять, что пошло не так.

rails g scaffold table field1:integer field2:string ....

      invoke  active_record
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-oracle_enhanced-adapter-1.4.1/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:7:in `rescue in <top (required)>': ERROR: ActiveRecord oracle_enhanced adapter could not load ruby-oci8 library. Please install ruby-oci8 gem. (LoadError)
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-oracle_enhanced-adapter-1.4.1/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:3:in `<top (required)>'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `block in require'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:236:in `load_dependency'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-oracle_enhanced-adapter-1.4.1/lib/active_record/connection_adapters/oracle_enhanced_connection.rb:112:in `<top (required)>'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `block in require'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:236:in `load_dependency'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-oracle_enhanced-adapter-1.4.1/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:36:in `<top (required)>'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `block in require'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:236:in `load_dependency'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-oracle_enhanced-adapter-1.4.1/lib/activerecord-oracle_enhanced-adapter.rb:12:in `block in <class:OracleEnhancedRailtie>'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/lazy_load_hooks.rb:42:in `each'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.2/lib/active_record/base.rb:718:in `<top (required)>'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.2/lib/rails/generators/named_base.rb:162:in `pluralize_table_names?'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.2/lib/rails/generators/named_base.rb:110:in `table_name'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.2/lib/rails/generators/active_record/model/model_generator.rb:17:in `create_migration_file'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/task.rb:22:in `run'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:118:in `invoke_task'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `block in invoke_all'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `each'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `map'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `invoke_all'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/group.rb:226:in `dispatch'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:109:in `invoke'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/group.rb:269:in `block in _invoke_for_class_method'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/shell.rb:74:in `with_padding'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/group.rb:258:in `_invoke_for_class_method'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/group.rb:150:in `_invoke_from_option_orm'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/task.rb:22:in `run'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:118:in `invoke_task'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `block in invoke_all'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `each'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `map'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `invoke_all'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/group.rb:226:in `dispatch'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/base.rb:389:in `start'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.2/lib/rails/generators.rb:170:in `invoke'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.2/lib/rails/commands/generate.rb:12:in `<top (required)>'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `block in require'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:236:in `load_dependency'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.2/lib/rails/commands.rb:29:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

gem list:

actionmailer (3.2.2)
actionpack (3.2.2)
activemodel (3.2.2)
activerecord (3.2.2)
activerecord-oracle_enhanced-adapter (1.4.1)
activeresource (3.2.2)
activesupport (3.2.2)
arel (3.0.2)
bigdecimal (1.1.0)
builder (3.0.0)
bundler (1.1.0)
coffee-rails (3.2.2)
coffee-script (2.2.0)
coffee-script-source (1.2.0)
erubis (2.7.0)
execjs (1.3.0)
hike (1.2.1)
i18n (0.6.0)
io-console (0.3)
journey (1.0.3)
jquery-rails (2.0.1)
json (1.6.5, 1.5.4)
mail (2.4.3)
mime-types (1.17.2)
minitest (2.5.1)
multi_json (1.1.0)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
rack-ssl (1.3.2)
rack-test (0.6.1)
rails (3.2.2)
railties (3.2.2)
rake (0.9.2.2)
rdoc (3.12, 3.9.4)
ruby-oci8 (2.1.0 x86-mingw32)
sass (3.1.15)
sass-rails (3.2.4)
sprockets (2.1.2)
sqlite3 (1.3.5 x86-mingw32)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
tzinfo (0.3.32)
uglifier (1.2.3)
ruby -r oci8 -e "OCI8.new('user', 'password', 'database').exec('select count(*) from table') do |r| puts r.join(','); end"

возвращает 0.86E2

Gemfile:

gem 'ruby-oci8', "~>2.1.0"
gem 'activerecord-oracle_enhanced-adapter', '~> 1.4.1'

Иду через IRB:

require 'rubygems' 
require 'active_record' 
ActiveRecord::Base.establish_connection( 
  :adapter => 'oracle_enhanced', 
  :database => 'database', 
  :username => 'user', 
  :password => 'password' 
)

class abc < ActiveRecord::Base 
  self.table_name = 'tablename' 
end 
puts "records found: #{abc.all.size}"

records found: 86
=> nil

person benjwlee    schedule 18.03.2012    source источник


Ответы (1)


У меня была аналогичная проблема с Ruby Mine:

У вас установлен путь Oracle clinet в:

DYLD_LIBRARY_PATH

Я установил их в своем терминале, но мне нужно было убедиться, что RubyMine установил переменные среды в моем профиле запуска:

DYLD_LIBRARY_PATH=/usr/local/oracle/instantclient10_2
NLS_LANG=AMERICAN_AMERICA.UTF8

Запуск скриптов может не искать переменные окружения в том же месте, что и терминал.

Возможно, вам придется запустить скрипт rails как:

env DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH NLS_LANG=$NLS_LANG rails g scaffold ...
person mpmeyer    schedule 20.03.2012
comment
Интересно, что я погуглил и нашел это: на Mac переменная среды — DYLD_LIBRARY_PATH, на Linux — LD_LIBRARY_PATH, а на Windows — PATH. Мой путь в окнах, где возникает эта проблема, установлен в C:\oracle\product\11.2.0\bin;C:\oracle\instantclient_11_2;C:\Program Files\MySQL\MySQL Server 5.5\bin;C:\Ruby193\ мусорное ведро - person benjwlee; 22.03.2012
comment
@benjwlee Вы говорите, что установленный вами Windows PATH теперь работает для вас или что он не работает для вас? - person Joseph Ravenwolfe; 16.10.2012