Devise + Facebook omniauth:在Devise :: OmniauthCallbacksController中找不到动作'facebook'

时间:2013-08-01 12:15:54

标签: ruby-on-rails ruby facebook devise omniauth

我在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

我甚至尝试重启服务器,但它没有帮助我。我正在关注this tutorial

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

2 个答案:

答案 0 :(得分:0)

将您的设计路线更改为

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

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

答案 1 :(得分:0)

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

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