2012-12-24 40 views
3

我一再嘗試使用nginx和獨角獸在ec2實例上設置我的rails應用程序。我發現nginx和獨角獸都設置正確;但是,在這兩臺機器上,我的Rails應用程序不想在生產環境中啓動。試圖在生產啓動的輸出是:由於ActiveRecord,Rails應用程序無法在生產環境中啓動

/Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:47:in `resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified) 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:41:in `resolve_string_connection' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:25:in `spec' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:129:in `establish_connection' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/railtie.rb:82:in `block (2 levels) in <class:Railtie>' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:26:in `block in on_load' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:25:in `each' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:25:in `on_load' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/railtie.rb:74:in `block in <class:Railtie>' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/initializable.rb:30:in `instance_exec' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/initializable.rb:30:in `run' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/initializable.rb:55:in `block in run_initializers' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/initializable.rb:54:in `each' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/initializable.rb:54:in `run_initializers' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/application.rb:136:in `initialize!' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/railtie/configurable.rb:30:in `method_missing' 
    from /Users/benvreed/Documents/rubydev/StudyPublic/config/environment.rb:5:in `<top (required)>' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `block in require' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require' 
    from /Users/benvreed/Documents/rubydev/StudyPublic/config.ru:4:in `block in <main>' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize' 
    from /Users/benvreed/Documents/rubydev/StudyPublic/config.ru:1:in `new' 
    from /Users/benvreed/Documents/rubydev/StudyPublic/config.ru:1:in `<main>' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `eval' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `parse_file' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:200:in `app' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands/server.rb:46:in `app' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:301:in `wrapped_app' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:252:in `start' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands/server.rb:70:in `start' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:55:in `block in <top (required)>' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:50:in `tap' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:50:in `<top (required)>' 
    from script/rails:6:in `require' 
    from script/rails:6:in `<main>' 

雖然,我清楚地做我database.yml文件中指定PostgreSQL的適配器:

# PostgreSQL. Versions 8.2 and up are supported. 
# 
# Install the pg driver: 
# gem install pg 
# On Mac OS X with macports: 
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config 
# On Windows: 
# gem install pg 
#  Choose the win32 build. 
#  Install PostgreSQL and put its /bin directory on your path. 
# 
# Configure Using Gemfile 
# gem 'pg' 
# 
development: 
    adapter: postgresql 
    encoding: unicode 
    host: localhost 
    database: study_development 
    pool: 5 

    # Connect on a TCP socket. Omitted by default since the client uses a 
    # domain socket that doesn't need configuration. Windows does not have 
    # domain sockets, so uncomment these lines. 
    #host: localhost 
    #port: 5432 

    # Schema search path. The server defaults to $user,public 
    #schema_search_path: myapp,sharedapp,public 

    # Minimum log levels, in increasing order: 
    # debug5, debug4, debug3, debug2, debug1, 
    # log, notice, warning, error, fatal, and panic 
    # The server defaults to notice. 
    #min_messages: warning 

# Warning: The database defined as "test" will be erased and 
# re-generated from your development database when you run "rake". 
# Do not set this db to the same as development or production. 
test: 
    adapter: postgresql 
    encoding: unicode 
    host: localhost 
    database: study_test 
    pool: 5 

production: 
    adapter: postgresql 
    encoding: unicode 
    host: localhost 
    database: study_production 
    pool: 5 

什麼是真正奇怪的是,它成功地運行在兩個開發和測試環境。我檢查了StackOverflow上的其他問題,大多數人都說這是間距問題;但是,我已經多次重做了database.yml文件,結果相同。

我的獨角獸和nginx文件是標準配置。

任何援助將不勝感激。在這個運行之前,我一直保持着立場。提前致謝。

RAILS_ENV

當通過執行RAILS_ENV=production rails c使用的Rails控制檯,運行RAILS_ENV生產:

NameError: uninitialized constant RAILS_ENV 
    from (irb):1 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands/console.rb:47:in `start' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands/console.rb:8:in `start' 
    from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:41:in `<top (required)>' 
    from script/rails:6:in `require' 
    from script/rails:6:in `<main>' 

Rails.env生產:

=> "production" 
+0

你能提供你的'RAILS_ENV'環境變量的值? –

+0

我提供了上面的輸出。 – codeblooded

+0

因此,Rails控制檯可以啓動,但通過獨角獸和nginx的服務器不能?我會開始挖掘那部分。 –

回答

0

我的設置使用此:

production: 
    adapter: pg 
    encoding: utf8 
    reconnect: false 
    database: my_app_name_production 
+0

試圖使用'adapter:pg'。它響應:'/Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in' require':請安裝pg適配器:'gem install activerecord-pg-adapter'(無法加載這樣的文件--active_record/connection_adapters/pg_adapter)(LoadError)'。我安裝了pg gem和postgresql。 – codeblooded

+0

如果你'gem install activerecord-pg-adapter'該怎麼辦? –

+0

它告訴我,它不可用。 '錯誤:無法在任何存儲庫中找到有效的gem'activerecord-pg-adapter'(> = 0)' – codeblooded

1

database.yml中的適配器應該是pg,而不是postgresql。

production: 
    adapter: pg 
    encoding: unicode 
    host: localhost 
    database: study_development 
0

您的database.yml設置沒問題。沒有什麼奇怪的。

如果開發模式運行無異常,則問題不在數據庫中。

嘗試精確檢查database.yml:可能存在無效/不可接受的*字符。


  • 一些符號是如此的相似:)с和c
0

分叉的錯誤! 也許一些緩存或日誌問題它表明我們的代碼中沒有任何錯誤。

我的團隊解決它。

  • 刪除項目

  • 混帳克隆項目

  • 配置數據庫。陽明海運

  • 啓動服務器

一切都還好!

同一個項目的錯誤消失了! 所以我們認爲這是env問題或者cach或log。

在這裏看到:(https://stackoverflow.com/posts/18695551/edit

相關問題