4

我在 SO 上找到了类似的线程,但没有一个能帮助我解决这个问题。我的路线看起来像:

devise_for :users do
    post '/users' => 'registrations#create', :as => 'user_registration'
end
devise_for :users, :controllers => {:omniauth_callbacks => "users/omniauth_callbacks"}

我也试过:

devise_for :users, :controllers => {:omniauth_callbacks => "omniauth_callbacks"}

但我仍然得到

The action 'facebook' could not be found for Devise::OmniauthCallbacksController

我什至尝试重新启动服务器,但这对我没有帮助。我正在关注本教程

omniauth_callbacks_controller.rb

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
    def facebook
        @user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)

        if @user.persisted?
            puts @user.inspect
            flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook"
            sign_in_and_redirect @user, :event => :authentication
        else
            session["devise.facebook_data"] = request.env["omniauth.auth"]
            redirect_to new_user_registration_url
        end
    end
end
4

2 回答 2

0

检查您的路线。也许它们会生成两次。尝试:

devise_for :users, :controllers => {:omniauth_callbacks => "users/omniauth_callbacks"}
devise_scope :users do
  post '/users' => 'registrations#create', :as => 'user_registration'
end
于 2013-08-01T13:30:52.170 回答
0

将您的设计路线更改为

  devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } 

以确保它与您的控制器定义匹配。

于 2013-08-01T13:28:25.870 回答