2012-03-18 19 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

私はルビー鉱山から実行されている同様の問題があった:

あなたはに設定されたOracle clinetパス持っていますか:私は私の端末でそれらを設定していた

DYLD_LIBRARY_PATH 

を、 RubyMineが実行中のプロファイルで環境変数を設定していることを確認しなければなりませんでした。

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

スクリプトを実行すると、端末と同じ場所で環境変数が検索されないことがあります。私はGoogleで検索して、この見つかっ

興味深い
env DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH NLS_LANG=$NLS_LANG rails g scaffold ... 
+0

:として

あなたはレールのスクリプトを実行する必要がありますMac上で を、環境変数はDYLD_LIBRARY_PATH、Linux上 、そのLD_LIBRARY_PATH と、WindowsのPATHにあります。 この問題が発生する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

+0

@benjwleeあなたが設定したWindows PATHが現在あなたのために働いているとか、あなたのために働いていないと言っていますか? –

関連する問題