Jedidja
Jedidja

Reputation: 16970

Why can't Cloud Foundry load mongo_mapper?

I've uploaded a simple Ruby test application to Cloud Foundry that works on my machine™, but it gives the following error on the site.

====> logs/stderr.log <====

/var/vcap/data/packages/dea_ruby18/3.1/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require': no such file to load -- mongo_mapper (LoadError)
    from /var/vcap/data/packages/dea_ruby18/3.1/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
    from recall.rb:2

I noticed that you need to have a Gemfile which is present in my root directory, but I'm not sure if it's getting used by the server.

source "http://rubygems.org"
gem "mongo_mapper"
gem "bson_ext"

So I'm guessing there are two possible reasons why this isn't working:

  1. I'm running Ruby 1.9, Cloud Foundry has 1.8 and there is something different? (I tried adding the 'require 'rubygems'' line to my file but no difference)
  2. My Gemfile is in the wrong format (or there is some other additional requirement for specifying where to get the mongo_mapper gem from).

How can this problem be solved?

Upvotes: 0

Views: 499

Answers (2)

Jeroen van Ingen
Jeroen van Ingen

Reputation: 1

  1. It could be a problem, but I strongly recommend to use the same Ruby version on your development environment and your production envirnoment. To make it easy you can use RVM to install Ruby 1.8 on your machine

  2. Did you do 'bundle install' in the root of your application? 'bundle install' looks in your Gemfile and install the gems. Note that if you group your gems in groups like 'development' and 'test', these gems will not be installed on production.

Upvotes: 0

polesen
polesen

Reputation: 713

I, like you, had trouble requiring 'mongo_mapper' on cloudfoundry. I solved my problems using Bundler and a Gemfile, as this page at cloudfoundry tells us to.

I now have "bundler" gem installed locally, and added this Gemfile at the root of the app tree:

source "http://rubygems.org"
gem 'sinatra'
gem 'json'
gem 'mongo'
gem 'mongo_mapper'

and instead of having the require lines in the .rb file, I only have this:

Bundler.require

before doing vmc push or update, you need to execute this:

bundle package
bundle install

I also did a little blog post about it.

Upvotes: 2

Related Questions