我正在尝试在我的Rails应用程序中实现Open Authorization,以便用户可以使用他们的LinkedIn帐户登录。当我点击链接转到LinkedIn授权页面,然后确认我的LinkedIn凭据时,我的应用程序中出现错误:
Unknown action
The action 'linkedin' could not be found for Devise::OmniauthCallbacksController
我几乎肯定问题在于我的路线文件。许多教程要求添加以下行:
devise_for :users, :controllers => { :omniauth_callbacks => "omniauth_callbacks" }
但是,我已在此处使用此行进行自定义Devise登录:
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
答案 0 :(得分:1)
使用
devise_for :users, :controllers => { :registrations => "registrations", :omniauth_callbacks => "omniauth_callbacks"}
这意味着您要自定义Devise的RegistrationsController
和OmniauthCallbacksController
。
例如:
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
...
end
和
class RegistrationsController < Devise::RegistrationsController
...
end