【问题标题】:How to deploy a Rails application with SQLite3 gem to Heroku如何将带有 SQLite3 gem 的 Rails 应用程序部署到 Heroku
【发布时间】:2018-09-10 12:14:55
【问题描述】:

我正在尝试将我的应用程序部署到 Heroku,但它失败了。我收到此错误:

Failed to install gems via Bundler.
remote:  !     Detected sqlite3 gem which is not supported on Heroku:
remote:  !     https://devcenter.heroku.com/articles/sqlite3
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.

这是我的 Gemfile:

source 'https://rubygems.org'

gem 'rails', '4.2.5'
gem 'sqlite3'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
#Authentication Gem -> https://github.com/thoughtbot/clearance
gem 'clearance', '~> 1.16.1'
gem 'bootstrap'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
#Gem for search
#https://github.com/karmi/retire
gem 'tire'
gem 'simple_form', '~> 3.4'
gem 'jquery-turbolinks'
gem "chartkick"

group :development, :test do
  gem 'byebug'
end

group :development do
  gem 'web-console', '~> 2.0'
  gem 'spring'
end

【问题讨论】:

标签: ruby-on-rails heroku rubygems


【解决方案1】:

Heroku 不支持 SQLite3。您可以改用 PostgreSQL。

添加sqlite3仅用于开发:

group :development do
   gem 'sqlite3'
end

group :test, :production do
    gem 'pg'
end

然后在提交更改之前运行bundle install

【讨论】:

  • 我是否必须为 postgresql 重新配置我的代码,还是可以正常工作?
  • 它会起作用,只需按照我的回答中的建议在 gemfile 中进行更改。
【解决方案2】:

Ganesh 让您开始正确...除了更新您的 gemfile,您还需要编辑您的 config/database.yml

宝石文件 =>

group :development, :test do
   gem 'sqlite3'
end

group :production do
    gem 'pg'
end

config/database.yml =>

default: &default
  adapter: sqlite3
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000

development:
  <<: *default
  database: db/development.sqlite3

test:
  <<: *default
  database: db/test.sqlite3

production:
  adapter: postgresql
  encoding: unicode
  host: localhost 
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  database: sample_production
  username: sample
  password: <%= ENV['SAMPLE_DATABASE_PASSWORD'] %>

其中 SAMPLE 通常是您的应用的名称...

【讨论】:

    猜你喜欢
    • 2014-04-07
    • 1970-01-01
    • 1970-01-01
    • 2012-10-12
    • 2016-12-04
    • 1970-01-01
    • 2015-12-25
    • 2018-03-31
    • 2012-10-30
    相关资源
    最近更新 更多