【发布时间】:2018-07-09 20:33:17
【问题描述】:
我一直在尝试将我的 Ruby on Rails 应用程序部署到 Heroku,但遇到了错误。非常感谢您提前提供的帮助!
我一直按照此链接中的说明部署我的应用程序:http://curriculum.railsbridge.org/intro-to-rails/deploying_to_heroku
我将 gemfile 更改为以下内容,然后运行
bundle install --without production
宝石文件:
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.3'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
gem 'sqlite3'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '~> 3.0.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :production do
gem 'pg'
gem 'rails_12factor'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'bootstrap-sass', '~> 3.3.7'
gem 'devise', '~> 4.2'
gem 'toastr-rails', "~> 1.0"
gem 'omniauth', '~> 1.6'
gem 'omniauth-facebook', '~> 4.0'
gem 'paperclip', '~> 5.1.0'
gem 'geocoder', '~> 1.4'
gem 'jquery-ui-rails', '~> 5.0'
gem 'momentjs-rails', '~> 2.17'
以下是 Heroku 的构建日志。它抱怨在 gemfile 中没有 gem 'pg',但我确实添加了它并且也做了捆绑安装。
Running: rake assets:precompile
rake aborted!
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).
从heroku构建日志
-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.3.4
###### WARNING:
You have the `.bundle/config` file checked into your repository
It contains local state like the location of the installed bundle
as well as configured git local gems, and other settings that should
not be shared between multiple checkouts of a single repo. Please
remove the `.bundle/` folder from your repo and add it to your `.gitignore` file.
https://devcenter.heroku.com/articles/bundler-configuration
-----> Installing dependencies using bundler 1.15.2
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.16.1). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
<Fetching a ton of things.....>
Bundle complete! 25 Gemfile dependencies, 82 gems now installed.
Gems in the groups development, test and production were not installed.
Bundled gems are installed into ./vendor/bundle.
Post-install message from paperclip:
##################################################
# NOTE FOR UPGRADING FROM 4.3.0 OR EARLIER #
##################################################
Paperclip is now compatible with aws-sdk >= 2.0.0.
If you are using S3 storage, aws-sdk >= 2.0.0 requires you to make a few small
changes:
* You must set the `s3_region`
* If you are explicitly setting permissions anywhere, such as in an initializer,
note that the format of the permissions changed from using an underscore to
using a hyphen. For example, `:public_read` needs to be changed to
`public-read`.
For a walkthrough of upgrading from 4 to 5 and aws-sdk >= 2.0 you can watch
http://rubythursday.com/episodes/ruby-snack-27-upgrade-paperclip-and-aws-sdk-in-prep-for-rails-5
Bundle completed (25.24s)
Cleaning up the bundler cache.
-----> Installing node-v6.11.1-linux-x64
-----> Detecting rake tasks
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
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).
/tmp/build_b5def35a67e05bc1af4c0bb3931868f9/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.6/lib/active_record/connection_adapters/connection_specification.rb:176:in `rescue in spec'
<more errors here>
/tmp/build_b5def35a67e05bc1af4c0bb3931868f9/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
Tasks: TOP => environment
(See full trace by running task with --trace)
!
! Precompiling assets failed.
!
! Push rejected, failed to compile Ruby app.
! Push failed
【问题讨论】:
-
这个 gem 由于
--skip production开关而被跳过(它只包含在 production 组中)。试试bundle install看看结果。 -
您还可以通过在开发和测试环境中安装 PostgreSQL 来避免这个问题(以及未来的许多问题)。 ActiveRecord 无法保护您免受许多可移植性问题的影响,因此使用一个数据库进行开发和测试,同时使用另一个数据库进行部署是疯狂的。
-
@Mareq,我做了捆绑安装,但仍然有同样的错误告诉我将
gem 'pg'添加到您的 Gemfile -
@StellaHan Rails 将根据您的
RAILS_ENV加载 Bundler 组。确保在您的 Heroku 配置中正确定义了RAILS_ENV,并确保相应的 Bundler 组中包含pggem。例如,如果您要部署到RAILS_ENV=staging,那么pggem 必须在staging捆绑器组中。gem 'pg', groups: %w[staging production]我认为您没有在 Heroku 配置中指定RAILS_ENV,因此 Rails 默认为development,而您的developmentBundler 组中没有pg。 -
尝试添加特定的 pg 版本。特别是不是最后一个(1.0.0),而是前一个(0.21.0)。
标签: ruby-on-rails ruby heroku heroku-postgres