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