1
votes

I have devise already set up in my application. I want to add omniauth-facebook gem (for facebook authentication). The set up works fine in development and staging environments, but given me the following error in my production environment:

Could not load 'omniauth'. Please ensure you have the omniauth gem >= 1.0.0 installed and listed in your Gemfile.
/home/slaxman/apps/itextbook/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require': cannot load such file -- omniauth (LoadError)

This warning seems to originate from this devise file.

My Gemfile

source 'https://rubygems.org'

gem 'rails', '3.2.11'

group :production do
    gem 'pg', '0.14.1'
    gem 'therubyracer','0.11.4'
    gem 'execjs', '1.4.0'
end

group :assets do
    gem 'sass-rails',   '~> 3.2.6'
    gem 'jquery-rails', '~> 2.2.1'
    gem 'coffee-rails', '~> 3.2.2'
    gem 'uglifier', '~> 1.3.0'
    gem 'bootstrap-sass', '~> 2.3.1.2'
    gem 'bootswatch-rails', '~> 0.5.0'
end

gem 'unicorn', '~> 4.6.2'
gem 'capistrano', '~> 2.14.2'
gem "multi_json", "~> 1.2.0"
gem 'devise' , '~> 2.2.4'
gem 'omniauth-facebook', '1.4.0'
gem 'cancan', '~> 1.6.8'
gem 'omniauth', '>= 1.0.0'

user.rb

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable, :omniauthable,
         :recoverable, :rememberable, :trackable, :validatable
end

In devise.rb

config.omniauth :facebook, OMNIAUTH_VAR['FACEBOOK_APP_ID'], OMNIAUTH_VAR['FACEBOOK_APP_SECRET'], scope: 'email'

Adding the following to devise.rb also does not work

require 'omniauth-facebook'
require 'omniauth'

Any help will be greatly appreciated. Thanks!

2

2 Answers

2
votes

Solved it! Apparently, it's a unicorn issue. Restarting unicorn doesn't help. It is necessary to stop and restart unicorn manually using the following commands:

/etc/init.d/unicorn_appname stop
/etc/init.d/unicorn_appname start

you can also do:

sudo service unicorn_appname stop
sudo service unicorn_appname start

replace 'appname' with the name of your app.

Answer Credit

0
votes

It's probably not in the right order, here's an example of my Gemfile that works. Hope this helps.

source 'https://rubygems.org'                                                      

gem 'rails', '3.2.3'                                                               
gem 'pg'                                                                           
gem 'jquery-rails'                                                                 
gem 'devise'                                                                                                                                                                                    
gem 'omniauth-facebook'                                                            
gem 'acts_as_votable'                                                              
gem 'gibbon'                                                                       
gem 'foreman'                                                                      
gem 'ruby-sendhub'                                                                 
gem 'bitly'                                                                        
gem 'rack-rewrite'                                                                 
gem 'twitter'                                                                      
gem 'hpricot'                                                                      
gem 'premailer-rails3'                                                             
gem 'kaminari'                                                                     

group :assets do                                                                   
  gem 'sass-rails',   '~> 3.2.3'                                                   
  gem 'coffee-rails', '~> 3.2.1'                                                   
  gem 'therubyracer', :platform => :ruby                                           
  gem 'uglifier', '>= 1.0.3'                                                       
end                                                                                

group :test, :development do                                                       
  gem "foreman"                                                                    
  gem "rspec-rails"                                                                
  gem "factory_girl_rails"                                                         
  gem "capybara"                                                                   
  gem "guard-rspec"                                                                
  gem "spork"                                                                      
  gem "guard-spork"                                                                
  gem "launchy"                                                                    
  gem "database_cleaner"                                                           
end