我正在尝试将twitter与devise集成到我的rails应用程序中。
但是,我收到此错误 动作' twitter'找不到Devise :: OmniauthCallbacksController
我的路线文件包含:
devise_for :conrollers => {:omniauth_callbacks => "omniauth_callbacks"}
我见过几个帖子但不太能解决这个问题。请帮忙。 这是我的控制器
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def twitter
raise request.env["omniauth.auth"].to_yaml
end
#alias_method :twitter, :all
端
答案 0 :(得分:0)
由于Devise::OmniauthCallbacksController
继承自DeviseController
,为什么不只是添加twitter
方法DeviseController
?
class DeviseController
def twitter
raise request.env["omniauth.auth"].to_yaml
end
end
或者你可以这样做:
class Devise::OmniauthCallbacksController
def twitter
raise request.env["omniauth.auth"].to_yaml
end
end
或者如果您有controllers/devise
目录,这可能有效:
module Devise
class OmniauthCallbacksController
def twitter
raise request.env["omniauth.auth"].to_yaml
end
end
end
答案 1 :(得分:0)
您应该在用户模型中进行设计调用。只需在那里添加另一个参数
devise :database_authenticatable, :registerable, :confirmable.......
......., :omniauth_providers: [:twitter]
答案 2 :(得分:0)
我得到了相同的错误消息,这就是我修复它的方式。我在OmniauthCallbacksController文件
中定义了一个Twitter方法。class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
skip_before_action :verify_authenticity_token
def sign_in_with(provider_name)
@user = User.from_omniauth(request.env["omniauth.auth"])
sign_in_and_redirect @user, :event => :authentication
set_flash_message(:notice, :success, :kind => provider_name) if is_navigational_format?
end
def facebook
sign_in_with "Facebook"
end
def github
sign_in_with "Github"
end
def linkedin
sign_in_with "LinkedIn"
end
def twitter
sign_in_with "Twitter"
end
def google_oauth2
sign_in_with "Google"
end
def developer
sign_in_with "Developer"
end
end