2012-03-18 66 views
3

rails g scaffold失敗,但oci腳本和irb數據查詢工作正常。無法弄清楚出了什麼問題。ActiveRecord oracle_enhanced適配器無法加載ruby-oci8庫

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 

回答

4

我從紅寶石礦上運行一個類似的問題:

你有甲骨文客戶爲例路徑設置:

DYLD_LIBRARY_PATH 

我讓他們在我的終端設置,但我必須確保RubyMine在我的運行配置文件中設置環境變量:

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

運行腳本可能不會在與終端相同的位置查找環境變量。

您可能需要運行軌道腳本:

env DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH NLS_LANG=$NLS_LANG rails g scaffold ... 
+0

有趣的我用Google搜索,發現這個: 在Mac上,該環境變量DYLD_LIBRARY_PATH, 在Linux上,它的LD_LIBRARY_PATH 和Windows路徑。發現此問題的Windows上的我的路徑設置爲C:\ oracle \ product \ 11.2.0 \ bin; C:\ oracle \ instantclient_11_2; C:\ Program Files \ MySQL \ MySQL Server 5.5 \ bin; C:\ Ruby193 \ bin – benjwlee 2012-03-22 03:33:45

+0

@benjwlee您是說您已設置的Windows PATH現在正在爲您工作,還是它不適合您? – 2012-10-16 16:12:01

相關問題