ruby-on-rails - 无法检测到 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_FILES
为true
我的 gemfile 中有pg
gem。(仅列为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
有人知道我在这里遗漏了什么或做错了什么吗?
解决方案
推荐阅读
- python - sqlalchemy session.query 奇怪 - 双重转义
- python - Python3 现在从 JSON 文件加载数据时抛出 ASCII 错误
- python - Django:NoReverseMatch -> 未找到“password_reset_done”的反向。“password_reset_done”不是有效的视图函数或模式名称
- java - 在纯 java 中调用 rest 调用
- magento2 - 废弃的购物车电子邮件未第二次发送
- php - xampp windows中的imagemagic安装问题
- c++ - 如何创建一个继承自 std::vector 的类
- ffmpeg - 通过管道将 ffmpeg 流传输到 sox rec
- c# - 本地管理员检索其他登录进程 MainWindowTitle
- google-cloud-storage - 使用谷歌云存储、谷歌计算引擎和外部网站提供文件