gpt4 book ai didi

ruby-on-rails-4 - Google omniauth 无法识别路径

转载 作者:行者123 更新时间:2023-12-02 04:36:50 32 4
gpt4 key购买 nike

我对 omniauth-google-oath2 gem 有疑问。

我的代码:

devise.rb

config.omniauth :google_oauth2, 'app_id','secret'

omniauth_callbacks_controller.rb

def google_oauth2
auth = env["omniauth.auth"]

@user = User.find_for_google_oauth2(request.env["omniauth.auth"], current_user)
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google"
sign_in_and_redirect @user, :event => :authentication
else
session["devise.google_uid"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end

我还在我的 user.rb 模型中为 find_for_google_oauth2 提供了方法。在我的 html.erb 中我写道:

<%= link_to "With Google", user_omniauth_authorize_path(:google_oauth2) %>

最后我有这个错误:没有路由匹配 {:controller=>"omniauth_callbacks", :action=>"passthru", :provider=>:google_oauth2, :format=>nil} missing required键:[:provider]

我的错误在哪里?感谢您的任何预付款!

最佳答案

检查用户模型

devise :omniauthable, omniauth_providers: [:google_oauth2]

它可能丢失或错误。

关于ruby-on-rails-4 - Google omniauth 无法识别路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21797512/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com