2

Ryan Bates が Railscasts の VPS エピソードにデプロイしたおかげで、Rails アプリのデモを VPS で実行しています。私のサーバーでは、このようなディレクトリ構造を作成し/home/username/apps、アプリケーションは次の場所にデプロイされまし/home/username/apps/appname.た。アプリ名フォルダー内には、Ryan のスクリプトによって作成されたさらに 3 つのフォルダーがあります (私は推測します)。

current  releases  shared

フォルダー内にcurrentは通常の Rails ディレクトリがあります。currentフォルダーに移動して実行するとrails crake db:seedエラーが発生します

 configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)

共有ディレクトリからトリガーされる

 apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activerecord-4.0.0.rc2/lib/active_record/connection_adapters

デモ アプリケーション (スキャフォールディング) が新しく作成されたエントリを保存して一覧表示しているため、これは異常なエラーであることがわかりました。アダプターの宣言に何か問題があります。

それが何であるか教えていただけますか?

この一般的なトピックを扱うアダプターを指定しないという質問データベース構成が既にあることに注意してください。ただし、その質問への回答は、データベースがまったく機能していない状況を扱っているようですが、私の状況ではそうではないようですケース。したがって、私はこの質問をそのスレッドと区別します。

これは私のdatabase.ymlファイルです

production:
  adapter:  postgresql
  encoding:  unicode
  database:  dodeploy_production
  pool:  5
  host:  localhost
  username:  michael
  password:  secretpassword

これは、Ryan がデプロイに使用するスクリプトです。私が見逃しているものを理解するのに役立つ情報がここにあるかもしれないので、私はそれを含めています.

require "bundler/capistrano"

server "198XXXX", :web, :app, :db, primary: true

set :application, "dodeploy"
set :user, "michael"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false

set :scm, "git"
set :repository, "git@github.com:Username/appname.git"
set :branch, "master"

default_run_options[:pty] = true
ssh_options[:forward_agent] = true

after "deploy", "deploy:cleanup" # keep only the last 5 releases

namespace :deploy do
  %w[start stop restart].each do |command|
    desc "#{command} unicorn server"
    task command, roles: :app, except: {no_release: true} do
      run "/etc/init.d/unicorn_#{application} #{command}"
    end
  end

  task :setup_config, roles: :app do
    sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
    sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
    run "mkdir -p #{shared_path}/config"
    put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
    puts "Now edit the config files in #{shared_path}."
  end
  after "deploy:setup", "deploy:setup_config"

  task :symlink_config, roles: :app do
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
  end
  after "deploy:finalize_update", "deploy:symlink_config"

  desc "Make sure local git is in sync with remote."
  task :check_revision, roles: :web do
    unless `git rev-parse HEAD` == `git rev-parse origin/master`
      puts "WARNING: HEAD is not the same as origin/master"
      puts "Run `git push` to sync changes."
      exit
    end
  end
  before "deploy", "deploy:check_revision"
end

エラー

実行するとrails c(またはrake db:seed)、これが得られます

home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activerecord-4.0.0.rc2/lib/active_record/connection_adapters/connection_specification.rb:52:in `resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activerecord-4.0.0.rc2/lib/active_record/connection_adapters/connection_specification.rb:46:in `resolve_string_connection'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activerecord-4.0.0.rc2/lib/active_record/connection_adapters/connection_specification.rb:30:in `spec'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activerecord-4.0.0.rc2/lib/active_record/connection_handling.rb:39:in `establish_connection'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activerecord-4.0.0.rc2/lib/active_record/railtie.rb:170:in `block (2 levels) in <class:Railtie>'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc2/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc2/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc2/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc2/lib/active_support/lazy_load_hooks.rb:44:in `each'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc2/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activerecord-4.0.0.rc2/lib/active_record/base.rb:322:in `<module:ActiveRecord>'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activerecord-4.0.0.rc2/lib/active_record/base.rb:22:in `<top (required)>'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc2/lib/active_support/dependencies.rb:228:in `require'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc2/lib/active_support/dependencies.rb:228:in `block in require'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc2/lib/active_support/dependencies.rb:213:in `load_dependency'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc2/lib/active_support/dependencies.rb:228:in `require'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/activerecord-4.0.0.rc2/lib/active_record/railtie.rb:61:in `block in <class:Railtie>'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/railties-4.0.0.rc2/lib/rails/railtie.rb:188:in `call'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/railties-4.0.0.rc2/lib/rails/railtie.rb:188:in `block in run_console_blocks'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/railties-4.0.0.rc2/lib/rails/railtie.rb:188:in `each'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/railties-4.0.0.rc2/lib/rails/railtie.rb:188:in `run_console_blocks'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/railties-4.0.0.rc2/lib/rails/application.rb:264:in `block in run_console_blocks'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/railties-4.0.0.rc2/lib/rails/engine/railties.rb:17:in `each'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/railties-4.0.0.rc2/lib/rails/engine/railties.rb:17:in `each'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/railties-4.0.0.rc2/lib/rails/application.rb:264:in `run_console_blocks'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/railties-4.0.0.rc2/lib/rails/engine.rb:431:in `load_console'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/railties-4.0.0.rc2/lib/rails/commands/console.rb:51:in `initialize'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/railties-4.0.0.rc2/lib/rails/commands/console.rb:9:in `new'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/railties-4.0.0.rc2/lib/rails/commands/console.rb:9:in `start'
    from /home/michael/apps/dodeploy/shared/bundle/ruby/1.9.1/gems/railties-4.0.0.rc2/lib/rails/commands.rb:66:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

アップデート

Ryan が Railscast で database.example.yml を作成した理由がわかりませんでした。彼はそれを構成しなかったので、ユーザー名とパスワードを追加する前に、元の database.yml ファイルのコピーとして残しました。

データベース.example.yml

development:
  adapter: postgresql
  encoding: unicode
  database: dodeploy_development
  pool: 5
  password:
test:
  adapter: postgresql
  encoding: unicode
  database: dodeploy_test
  pool: 5
  password:

production:
  adapter: postgresql
  encoding: unicode
  database: dodeploy_production
  pool: 5
  password:

これはnginx.confファイルです

upstream unicorn {
  server unix:/tmp/unicorn.dodeploy.sock fail_timeout=0;
}

server {
  listen 80 default deferred;
  # server_name example.com;
  root /home/michael/apps/dodeploy/current/public;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @unicorn;
  location @unicorn {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://unicorn;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

アップデート。

これは connection_specification.rb のメソッドです

     def resolve_hash_connection(spec) # :nodoc:
          spec = spec.symbolize_keys

          raise(AdapterNotSpecified, "database configuration does not specify adapter") unless spec.key?(:adapter)

          path_to_adapter = "active_record/connection_adapters/#{spec[:adapter]}_adapter"
          begin
            require path_to_adapter
          rescue Gem::LoadError => e
            raise Gem::LoadError, "Specified '#{spec[:adapter]}' for database adapter, but the gem is not loaded. Add `$
          rescue LoadError => e
 raise LoadError, "Could not load '#{path_to_adapter}'. Make sure that the adapter in config/database.yml is$
          end

          adapter_method = "#{spec[:adapter]}_connection"

          ConnectionSpecification.new(spec, adapter_method)
        end
4

1 に答える 1

4

コマンド実行時に本番環境を指定して動作させました

RAILS_ENV=production rails console

RAILS_ENV=production rake db:seed

アプリが機能していたので、これは異常だと思いました。

于 2013-06-15T14:42:54.877 に答える