Reputation: 115
My application works locally but I am having problems trying to push it to Heroku. I am using mLab and Mongoid in my Rails 5 application. When I enter:
git push heroku master
I get the following errors:
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
works fine.
Here is my config/application.rb file:
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
My rakefile:
require_relative 'config/application'
Rails.application.load_tasks
In case it's needed here's the production part of mongoid.yml:
# mongoid
#
production:
clients:
default:
uri: mongodb://<username>:<password>@ds133340.mlab.com:33340/okclone
options:
connect_timeout: 15
Note: I put in my actual username and password in the uri above.
And my gemfile, in case it's related:
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]
Edit: I also tried running
heroku config:set PROD_MONGODB = mongodb://dbuser:dbpass@host1:port1,host2:port2/dbname
with my mLab URI added in but that didn't seem to fix the problem.
Upvotes: 0
Views: 289
Reputation: 115
The problem turned out to be with my gemfile. Because the mongoid and bson gems were only under test and development, they weren't accessible in production. Here is the updated 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'
gem 'mongoid', '~> 6.1.0'
gem 'bson_ext'
group :development, :test do
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]
Upvotes: 1