首页 > 解决方案 > 无法检测到 rake 任务,NameError: undefined local variable or method 'config' for main:Object

问题描述

我正在尝试将我的应用程序部署到 Heroku。(我以前从未这样做过)。我最初有一个sqlite数据库,但后来发现你必须有一个postgres数据库才能这样做。所以我把所有东西都打开了,现在当我尝试运行时,我遇到git push heroku master了这个错误。`无法检测到 rake 任务

当我尝试运行时bundle exec rake -P,一切似乎都运行良好。

我的错误日志是

remote:  !     Could not detect rake tasks
remote:  !     ensure you can run `$ bundle exec rake -P` against your app
remote:  !     and using the production group of your Gemfile.
remote:  !     rake aborted!
remote:  !     NameError: undefined local variable or method `config' for main:Object
remote:  !     /tmp/build_154932c2286286ad0f0668edbed5dc08/config/application.rb:6:in `<top (required)>'
remote:  !     /tmp/build_154932c2286286ad0f0668edbed5dc08/Rakefile:4:in `require_relative'
remote:  !     /tmp/build_154932c2286286ad0f0668edbed5dc08/Rakefile:4:in `<top (required)>'
remote:  !     /tmp/build_154932c2286286ad0f0668edbed5dc08/vendor/bundle/ruby/2.4.0/gems/rake-13.0.1/lib/rake/rake_module.rb:29:in `load'
remote:  !     /tmp/build_154932c2286286ad0f0668edbed5dc08/vendor/bundle/ruby/2.4.0/gems/rake-13.0.1/lib/rake/rake_module.rb:29:in `load_rakefile'
remote:  !     /tmp/build_154932c2286286ad0f0668edbed5dc08/vendor/bundle/ruby/2.4.0/gems/rake-13.0.1/lib/rake/application.rb:703:in `raw_load_rakefile'
remote:  !     /tmp/build_154932c2286286ad0f0668edbed5dc08/vendor/bundle/ruby/2.4.0/gems/rake-13.0.1/lib/rake/application.rb:104:in `block in load_rakefile'
remote:  !     /tmp/build_154932c2286286ad0f0668edbed5dc08/vendor/bundle/ruby/2.4.0/gems/rake-13.0.1/lib/rake/application.rb:186:in `standard_exception_handling'
remote:  !     /tmp/build_154932c2286286ad0f0668edbed5dc08/vendor/bundle/ruby/2.4.0/gems/rake-13.0.1/lib/rake/application.rb:103:in `load_rakefile'
remote:  !     /tmp/build_154932c2286286ad0f0668edbed5dc08/vendor/bundle/ruby/2.4.0/gems/rake-13.0.1/lib/rake/application.rb:82:in `block in run'
remote:  !     /tmp/build_154932c2286286ad0f0668edbed5dc08/vendor/bundle/ruby/2.4.0/gems/rake-13.0.1/lib/rake/application.rb:186:in `standard_exception_handling'
remote:  !     /tmp/build_154932c2286286ad0f0668edbed5dc08/vendor/bundle/ruby/2.4.0/gems/rake-13.0.1/lib/rake/application.rb:80:in `run'
remote:  !     /tmp/build_154932c2286286ad0f0668edbed5dc08/vendor/bundle/ruby/2.4.0/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
remote:  !     ./vendor/bundle/bin/rake:29:in `load'
remote:  !     ./vendor/bundle/bin/rake:29:in `<main>'

我已经进入herokue设置并将其设置RAILS_SERVE_STATIC_FILEStrue

我的 gemfile 中有pggem。(仅列为gem 'pg'

我的数据库文件是

default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5

development:
  host: 127.0.0.1
  adapter: postgresql
  encoding: unicode
  database: myDatabase_development
  username: username
  timeout: 5000
  pool: 5

test:
  adapter: postgresql
  encoding: unicode
  database: myDatabase_testing
  username: username
  timeout: 5000


production:
  url:  <%= ENV["DATABASE_URL"] %>
  pool: <%= ENV["DB_POOL"] || ENV['RAILS_MAX_THREADS'] || 5 %>
  database: myDatabase_production
  username: username
  timeout: 5000
  pool: 5

我的生产文件是

Rails.application.configure do
  config.cache_classes = true
  config.eager_load = true
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true
  config.public_file_server.enabled = true
  config.log_level = :debug
  config.log_tags = [ :request_id ]
  config.action_mailer.perform_caching = false
  config.i18n.fallbacks = true
  config.active_support.deprecation = :notify
  config.log_formatter = ::Logger::Formatter.new

  if ENV["RAILS_LOG_TO_STDOUT"].present?
    logger           = ActiveSupport::Logger.new(STDOUT)
    logger.formatter = config.log_formatter
    config.logger = ActiveSupport::TaggedLogging.new(logger)
  end
  config.active_record.dump_schema_after_migration = false
end

当我运行时RAILS_ENV=production bundle exec rake assets:precompile,(认为我有一个预编译问题)。一切都按原样编译。

最后我的application.rb也只有这个信息。

require_relative 'boot'

require 'csv'
require 'rails/all'

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

module DowntownInventoryApp
  class Application < Rails::Application

    config.assets.initialize_on_precompile = false
    # 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.
  end
end

有人知道我在这里遗漏了什么或做错了什么吗?

标签: ruby-on-railsrubypostgresqlherokurubygems

解决方案


推荐阅读