【问题标题】:Postgres gem not loaded on initial Rails 4 app deploymentPostgres gem 未在初始 Rails 4 应用程序部署中加载
【发布时间】:2016-02-09 11:54:27
【问题描述】:

我的 Rails 4 应用程序目前在我的本地机器和 heroku 上运行。现在我尝试设置一个 ubutunu 14 服务器。对于部署,我正在使用 capistrano,并且我的本地计算机和服务器之间的连接已经设置。目前我正在尝试使用此命令进行初始部署:

cap production deploy:initial

我在某个时候收到以下错误:

Running ~/.rvm/bin/rvm default do bundle exec rake assets:precompile on MYIP
DEBUG Command: cd /home/deploy/apps/savoir/releases/20160209113448 && ( export RAILS_ENV="production" ; ~/.rvm/bin/rvm default do bundle exec rake assets:precompile )
DEBUG        rake aborted!
DEBUG        Gem::LoadError: Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).

我的 gemfile 看起来像这样:

source 'http://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.8'
# Use sqlite3 as the database for Active Record
# gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0.1'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer',  platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0',          group: :doc

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin]

gem 'bootstrap-sass', '~> 3.3.5.1'
gem 'autoprefixer-rails'
gem 'bootstrap-sass-extras'
gem 'bootstrap-daterangepicker-rails'
gem 'bootstrap-datepicker-rails'

gem 'simple_form'
gem 'nested_form'

gem 'ckeditor'
gem 'coffee-script-source', '1.8.0'
gem 'carrierwave', github:'carrierwaveuploader/carrierwave'
gem 'carrierwave-crop'
gem 'rmagick'
gem 'mini_magick'

gem 'momentjs-rails'
gem 'gon'

gem 'jquery-ui-rails'
gem 'jquery-fileupload-rails'
gem 'jquery-turbolinks'
gem 'jquery-validation-rails'

gem 'devise'

gem 'ransack'
gem 'will_paginate'

gem 'rails_12factor'
gem 'pg', '~> 0.18.3'   

gem 'geocoder'
gem 'gmaps4rails'
gem 'underscore-rails'

group :development do
    gem 'capistrano',         require: false
    gem 'capistrano-rvm',     require: false
    gem 'capistrano-rails',   require: false
    gem 'capistrano-bundler', require: false
    gem 'capistrano3-puma',   require: false
end

gem 'puma'

还有我的 database.yml:

development:
  adapter: postgresql
  database: savoir_development
  pool: 5
  username: postgres
  password: root

test:
  adapter: postgresql
  database: savoir_test
  pool: 5
  timeout: 5000
  username: postgres
  password: root

production:
  adapter: postgresql
  database: deploy
  pool: 5
  timeout: 5000
  username: USER
  password: PASSWORD

据我所知,gemfile 和 database.yml 应该没问题。谁能找到我犯的错误?我发现了一些其他主题可以解决这个问题,但它们对我的情况没有帮助。

【问题讨论】:

  • gem 文件中有 sqlite3 和 pg,我想你需要在 gemfile 中添加 pg gem 到生产环境,gem 'pg',group: :production,然后是 sqlite 3 , gem 'sqlite3', group: [:development, :test],或者如果你不使用它,就干脆删除 sqlite3。
  • 感谢您的回答。 sqlite3 gem 被注释掉了。
  • 它在 gemlock 文件中?
  • 不,它不在我的宝石锁里。

标签: ruby-on-rails postgresql deployment ubuntu-14.04


【解决方案1】:

好的,我找到了解决方案。

由于我在本地机器上使用 windows,rails 使用了这个版本的 pg:

//Gemlock.lock
pg (0.18.4-x86-mingw32)

改成

//Gemlock.lock
pg (0.18.4)

并将其推送到 git 解决了我的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-20
    • 2015-10-23
    • 2013-08-13
    • 2015-01-27
    • 1970-01-01
    • 1970-01-01
    • 2016-02-27
    • 1970-01-01
    相关资源
    最近更新 更多