How to get facebook login working with devise, omniauth - cannot overcome controller error

I am working on getting Facebook working with devise and omniauth. I have been trying to figure this out for days now without success. When I press the 'Facebook connect' button, the login page comes up. Once an FB email is entered along with a password, I am redirected to a page with the url suffix "{root domain}/users/sign_in#-" along with an error that says " translation missing: en.devise.authentications.user.failure." Users are not being added to the database. I have been at this for a while and it is very frustrating so far. I have routes as follows:


new_user_session GET    /users/sign_in(.:format)    sessions#new

user_session POST       /users/sign_in(.:format)    sessions#create

destroy_user_session DELETE /users/sign_out(.:format) sessions#destroy

user_omniauth_authorize /users/auth/:provider(.:format) authentications#passthru {:provider=>/facebook/}

user_omniauth_callback  /users/auth/:action/callback(.:format)  authentications#(?-mix:facebook)

In devise.rb I have:

config.omniauth :facebook, Facebook::APP_ID.to_s, Facebook::SECRET.to_s
require 'devise/orm/active_record'
config.authentication_keys = [ :email ]
config.http_authenticatable = false
config.http_authenticatable_on_xhr = false
config.navigational_formats = [:js, :html, :json]
config.token_authentication_key = :auth_token
config.sign_out_via = :delete

The config initializers omniauth.rb

if Rails.env == 'development' || Rails.env == 'test'
  Rails.application.config.middleware.use OmniAuth::Builder do
    provider :facebook, 'XXXXXX', 'XXXXXXXXXXXXX'
  # Production
  Rails.application.config.middleware.use OmniAuth::Builder do
    provider :facebook, 'PRODUCTION_APP_ID', 'PRODUCTION_APP_SECRET'

In users.rb I have:

   def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
        data = access_token.extra.raw_info
        if user = User.where(:email =>
            if user.facebook_id.nil?
                    user.facebook_id =
        else # Create a user with a stub password. 
            token = Devise.friendly_token[0,20]
        User.create!(:email =>, :name=>, :facebook_id=>, :password => token, :password_confirmation=> token)

    def self.new_with_session(params, session)
       super.tap do |user|
         if data = session["devise.facebook_data"] && session["devise.facebook_data"]["extra"]["raw_info"]
    = data["name"]
    = data["email"]
             user.facebook_id = session["devise.facebook_data"]["extra"]["raw_info"]['id']

In authentications controller (which is derived from the omniauth callbacks controller)

class AuthenticationsController < Devise::OmniauthCallbacksController
  def facebook
    # You need to implement the method below in your model
    @user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)

    if @user.persisted?
      flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook"
      sign_in_and_redirect @user, :event => :authentication
      session["devise.facebook_data"] = request.env["omniauth.auth"]
      flash[:notice] = "Please register an account first!"
      redirect_to "/"

In the development log, there is :

Started GET "/users/auth/facebook" for at 2013-01-22 20:09:28 -0500

Started GET "/users/auth/facebook/callback? state=blah&code=blah" for at     
2013-01-22 20:09:29 -0500
Processing by AuthenticationsController#failure as HTML
Parameters: {"state"=>"blah", "code"=>"blah"}
Redirected to
Completed 302 Found in 2ms (ActiveRecord: 0.0ms)

On the Facebook app settings page, I have :

App Domain: (empty)

Site URL : http: //

and sandbox mode is enabled. I would appreciate any help at all in this. I have tried everything possible and check many sites, but I'm at a block.


There is a Devise issue on something like your immediate error message (found by web searching the "en.devise.authentications" part).

The Rails Internationalization (I18n) API guide describes the translations load path.

Apparently, here, Devise's lib/en.yml hasn't supplied the English string that Devise needs, but you can supply it yourself.

You haven't given us the contents of your config/locales/en.yml file, but that's where you can add:

        failure: User authentication failure

You can change the failure message to whatever you want.

See this example for the general i18n YAML format.

That should answer your question and solve your immediate error message.

Need Your Help

How to convert to

java sql datetime date

I am trying to use java.util.Date as input and then creating a query with it - so I need java.sql.Date.

How to start Qt development on Windows, but targeting Maemo 5?

windows qt nokia maemo qt-maemo

I've recently heard about Qt and read about how fun it is to develop with. By the way, I'm also buying a Nokia N900 and I heard that its operating system, Maemo 5, supports Qt quite nicely, so I th...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.