“Cannot load such file” error when deploying Rails

2019-08-01 09:49发布

I'm using a gem for gmail in my Rails app. My Gemfile contains:

gem 'gmail-api-ruby', :require => 'Gmail'

And in my controller, I initialize the gem with (using devise/omniauth to get the refresh_token from Google):

Gmail.client_id = ENV['CLIENT_ID']
Gmail.client_secret = ENV['CLIENT_SECRET']
Gmail.refresh_token = current_user.refresh_token

This works fine in development, but when I deploy to Heroku, I get the following error:

/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.7.12/lib/bundler/runtime.rb:76:in `require': cannot load such file -- Gmail (LoadError)

I cannot figure out why. Should I be requiring the gem somewhere else in my app?

  • Ruby 2.2.0
  • Bundler: 1.8.5
  • Rails: 4.2.0

2条回答
成全新的幸福
2楼-- · 2019-08-01 10:37

Just remove useless require option from your Gemfile because bundler can load classes inside of this gem without specify require option in your case.

gem 'gmail-api-ruby', '~> 0.0.10'

and run bundle install.

FYI: read section about require option here.

查看更多
爷的心禁止访问
3楼-- · 2019-08-01 10:38

require is case sensitive if the underlying filesystem is case sensitive (which it is on linux, which is what underpins heroku)

Change to :require => 'gmail' instead of Gmail and you should be ok.

查看更多
登录 后发表回答