2

我有一个带有 Vue 前端和 Rails 后端的项目。它只是后端的一个非常简单的 API,没有数据库或任何东西。它在本地运行良好,但现在我想将它部署在 Heroku 上。

但是,当我运行它时,我收到以下错误。

-----> Detecting rake tasks
 !
 !     Could not detect rake tasks
 !     ensure you can run `$ bundle exec rake -P` against your app
 !     and using the production group of your Gemfile.
 !     rake aborted!
 !     URI::InvalidURIError: bad URI(is not URI?): ://user:pass@127.0.0.1/dbname
  ...
  ...
/activerecord-6.0.2.1/lib/active_record/railties/databases.rake

根据各种 SO 帖子/Heroku 文档,我已经尝试过:

  • bundle exec rake -P RAILS_ENV=production- 一切看起来都不错
  • rake在 Gemfile 中添加依赖项
  • 删除sqliteGemfile 中的依赖项
  • 从 Gemfile.lock 中删除 BUNDLED WITH

但仍然是同样的错误。

我想这与我的数据库配置有关,但我的项目中没有任何数据库,所以这似乎是一项不必要的任务。我尝试从我的 Gemfile 中注释掉 railties,但它仍然作为其他 gem 的依赖项存在。当我在进行此更改后进行部署时,它仍然会执行相同的任务并失败。

链接到回购分支

4

2 回答 2

0

而不是require 'rails/all'需要所有 Railties,包括 ActiveRecord,您需要明确要求您要使用的 railties:

require File.expand_path('../boot', __FILE__)

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
# require "active_record/railtie"
# require "active_storage/engine"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_mailbox/engine"
# require "action_text/engine"
require "action_view/railtie"
require "action_cable/engine"
require "sprockets/railtie"

module Draw
  class Application < Rails::Application
    # You don't need this nonsense since you don't even have config/application.yml
    #  ENV.update YAML.load_file('config/application.yml')[Rails.env] rescue {}
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    # config.time_zone = 'Central Time (US & Canada)'

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    # config.i18n.default_locale = :de

    # Do not swallow errors in after_commit/after_rollback callbacks.
    # config.active_record.raise_in_transactional_callbacks = true
  end
end

如果你不想使用 ActiveRecord,你可以去掉/dband /config/database.yml

您也不需要gem 'rake'在 Gemfile 中添加 have,因为 rails 无论如何都依赖于它。

于 2020-02-02T15:04:31.517 回答
0

需要从项目中完全删除 ActiveRecord 的使用。正如Max 评论的那样,在新应用程序中,这可以通过做来完成rails new app_name --skip-active-record --api,要为现有项目执行此操作,请参阅此说明

于 2020-02-03T14:39:45.423 回答