我试图在我的Rails应用程序中实现开放授权,以便用户可以使用他们的LinkedIn帐户登录。当我点击链接进入LinkedIn授权页面,然后确认我的LinkedIn凭据时,我在应用程序中得到一个错误:
Unknown action
The action 'linkedin' could not be found for Devise::OmniauthCallbacksController
我几乎肯定问题在于我的路由文件。许多教程都要求添加以下行:
devise_for :users, :controllers => { :omniauth_callbacks => "omniauth_callbacks" }
然而,我已经有了这一行自定义的设计登录:
devise_for :users, :controllers => { :registrations => "registrations" }
我试着切换它们,但没有工作(如我所料)。有没有办法把这两个表述结合起来?
谢谢!
omniauth_callbacks_controller问题:The action 'linkedin' could not be found for OmniauthCallbacksController
class OmniauthCallbacksController < ApplicationController
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def linkedin
auth = env["omniauth.auth"]
@user = User.connect_to_linkedin(request.env["omniauth.auth"],current_user)
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success"
sign_in_and_redirect @user, :event => :authentication
else
session["devise.linkedin_uid"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
end
end
使用
devise_for :users, :controllers => { :registrations => "registrations", :omniauth_callbacks => "omniauth_callbacks"}
这意味着您正在定制设计的RegistrationsController
和OmniauthCallbacksController
。
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
...
end
和
class RegistrationsController < Devise::RegistrationsController
...
end