【问题标题】:Google omniauth doesn't recognize pathGoogle omniauth 无法识别路径
【发布时间】:2014-03-14 21:15:19
【问题描述】:

我对 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) %>

最后我有这个错误:No route matches {:controller=>"omniauth_callbacks", :action=>"passthru", :provider=>:google_oauth2, :format=>nil} missing required键:[:provider]

我的错误在哪里? 感谢您的提前!

【问题讨论】:

    标签: ruby-on-rails-4 omniauth


    【解决方案1】:

    检查用户模型

    devise :omniauthable, omniauth_providers: [:google_oauth2]
    

    它可能丢失或错误。

    【讨论】:

      【解决方案2】:

      我解决了我的问题。这很愚蠢:) 我刚刚重新启动了本地 Rails 服务器,一切正常。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-05-25
        • 2016-09-11
        • 2015-04-19
        • 2019-07-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-12
        相关资源
        最近更新 更多