我的应用程序在本地工作,但我在尝试将其推送到Heroku时遇到问题。我在我的Rails 5应用程序中使用mLab和Mongoid。当我输入:Heroku错误 - NameError:未初始化的常量PracticeApp :: Application :: Mongoid
git push heroku master
我收到以下错误:
r.rb:102:in `load_rake_tasks!': Could not detect rake tasks (LanguagePack::Helpers::RakeRunner::CannotLoadRakefileError)
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: uninitialized constant PracticeApp::Application::Mongoid
remote: /tmp/build_7a8e6644d3ecbd6336fe612855f87f95/practice_app/config/application.rb:21:in `<class:Application>'
remote: /tmp/build_7a8e6644d3ecbd6336fe612855f87f95/practice_app/config/application.rb:20:in `<module:PracticeApp>'
remote: /tmp/build_7a8e6644d3ecbd6336fe612855f87f95/practice_app/config/application.rb:19:in `<top (required)>'
remote: /tmp/build_7a8e6644d3ecbd6336fe612855f87f95/practice_app/Rakefile:4:in `require_relative'
remote: /tmp/build_7a8e6644d3ecbd6336fe612855f87f95/practice_app/Rakefile:4:in `<top (required)>'
bundle exec rake -P
工作正常。
这里是我的config/application.rb中的文件:
require_relative 'boot'
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
# require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "action_cable/engine"
require "sprockets/railtie"
require "rails/test_unit/railtie"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module PracticeApp
class Application < Rails::Application
Mongoid.load!("./config/mongoid.yml", :production)
end
end
我的Rakefile:
require_relative 'config/application'
Rails.application.load_tasks
在情况下,它需要在这里是mongoid.yml生产的部分:
# mongoid
#
production:
clients:
default:
uri: mongodb://<username>:<password>@ds133340.mlab.com:33340/okclone
options:
connect_timeout: 15
注意:我把我的实际用户名和密码放在uri ab OVE。
而我的Gemfile,在情况下,它涉及:
source 'https://rubygems.org'
gem 'rails', '5.0.1'
gem 'puma', '3.4.0'
gem 'sass-rails', '5.0.6'
gem 'uglifier', '3.0.0'
gem 'coffee-rails', '4.2.1'
gem 'jquery-rails', '4.1.1'
gem 'turbolinks', '5.0.1'
gem 'jbuilder', '2.4.1'
group :development, :test do
gem 'mongoid', '~> 6.1.0'
gem 'bson_ext'
gem 'byebug', '9.0.0', platform: :mri
end
group :development do
gem 'web-console', '3.1.1'
gem 'listen', '3.0.8'
gem 'spring', '1.7.2'
gem 'spring-watcher-listen', '2.0.0'
end
group :test do
gem 'rails-controller-testing', '0.1.1'
gem 'minitest-reporters', '1.1.9'
gem 'guard', '2.13.0'
gem 'guard-minitest', '2.4.4'
end
group :production do
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]
编辑:我也试着运行
heroku config:set PROD_MONGODB = mongodb://dbuser:[email protected]:port1,host2:port2/dbname
我MLAB URI中,但似乎并没有给解决问题增加。
噢好吧,会的。 – xeno7