I'd like to elaborate on the (correct) answer @jeroen-van-dijk gave above which worked for me.
In config/routes.rb, add a new route in the devise_for block:
devise_for :users, :controllers => {
:omniauth_callbacks => "user_omniauth_callbacks" } do
...
get '/users/connect/:network', :to => redirect("/users/auth/%{network}"),
:as => 'user_oauth_connect'
end
Then change your "login using facebook" link to use the new route:
<!-- before it linked to user_omniauth_authorize_path -->
<%= link_to "Sign in using Facebook", user_oauth_connect_path(:facebook) %>
In app/controllers/user_omnniauth_callbacks_controller.rb
class UserOmniauthCallbacksController < Devise::OmniauthCallbacksController
include Devise::Controllers::Rememberable
def facebook
@user = User.find(...)
...
remember_me(@user) # set the remember_me cookie
end
end
This solution works well for me using Rails 3.1 and Devise 1.4.9.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…