Ruby on rails 错误\u太多\u重定向使用OmniAuth/Desive/Rails登录
我正试图按照以下说明将Facebook登录添加到我的Rails 4站点: 我目前正在使用Desive和Pundit进行授权和验证。尽管我已经尽我最大的能力遵循了说明,但我还是犯了一个错误。当我单击“使用Facebook登录”按钮时,会弹出一个窗口,询问电子邮件/密码,当我提交该信息时,会出现一个错误页面,内容如下: [MyApp.com]页面不工作 [MyApp.com]重定向您的次数太多 尝试:Ruby on rails 错误\u太多\u重定向使用OmniAuth/Desive/Rails登录,ruby-on-rails,facebook,devise,omniauth,pundit,Ruby On Rails,Facebook,Devise,Omniauth,Pundit,我正试图按照以下说明将Facebook登录添加到我的Rails 4站点: 我目前正在使用Desive和Pundit进行授权和验证。尽管我已经尽我最大的能力遵循了说明,但我还是犯了一个错误。当我单击“使用Facebook登录”按钮时,会弹出一个窗口,询问电子邮件/密码,当我提交该信息时,会出现一个错误页面,内容如下: [MyApp.com]页面不工作 [MyApp.com]重定向您的次数太多 尝试: 重新加载页面 清除Cookie错误\u太多\u重定向 似乎我引入了一个重定向循环,但我并不真
- 重新加载页面
- 清除Cookie错误\u太多\u重定向
Rails.application.routes.draw do
get 'home/index'
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks", sessions: "sessions" }
resources :movies
root 'home#index'
end
omniauth_callbacks_controller.rb:
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
before_filter :authenticate_user, :except => [:new, :create, :destroy]
def facebook
# You need to implement the method below in your model (e.g. app/models/user.rb)
@user = User.from_omniauth(request.env["omniauth.auth"])
if @user.persisted?
sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
else
session["devise.facebook_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
def failure
redirect_to root_path
end
end
我的用户模型(user.rb):
我也遇到了同样的问题!收到此错误后,您是否能够重新加载页面,并且该页面实际上已让您登录?如果是的话,那就是我所拥有的。登录成功了,但重定向效果不好 您是否已在登录后重定向页面的
应用程序控制器.rb的路径中为(资源)
添加签名后的?我有,这就是重定向发生的原因
我的解决方案是修复if语句,以包含正确的推荐人。我刚刚添加了| | request.referer.include?(“谷歌”)
,当然您可能需要在referer url中将其更改为“facebook”帐户
def after_sign_in_path_for(resource)
sign_in_url = new_user_session_url
if request.referer == sign_in_url || request.referer.include?("google")
super
goals_path
else
stored_location_for(resource) || request.referer || root_path
end
end
现在。。。如果你没有使用这个函数,那么我的答案对你来说是无用的。祝你好运。我也遇到了这个问题!收到此错误后,您是否能够重新加载页面,并且该页面实际上已让您登录?如果是的话,那就是我所拥有的。登录成功了,但重定向效果不好
您是否已在登录后重定向页面的应用程序控制器.rb的路径中为(资源)
添加签名后的?我有,这就是重定向发生的原因
我的解决方案是修复if语句,以包含正确的推荐人。我刚刚添加了| | request.referer.include?(“谷歌”)
,当然您可能需要在referer url中将其更改为“facebook”帐户
def after_sign_in_path_for(resource)
sign_in_url = new_user_session_url
if request.referer == sign_in_url || request.referer.include?("google")
super
goals_path
else
stored_location_for(resource) || request.referer || root_path
end
end
现在。。。如果你没有使用这个函数,那么我的答案对你来说是无用的。祝你好运。这是很久以前的事了,但我相信有些文档已经过时了。我觉得我最终简化了很多代码。也许omniauth后来得到了更新……这是很久以前的事了,但我相信有些文档已经过时了。我觉得我最终简化了很多代码。也许omniauth稍后会得到更新。。。
%button
= link_to "Log in with Facebook", user_omniauth_authorize_path(:facebook)
def after_sign_in_path_for(resource)
sign_in_url = new_user_session_url
if request.referer == sign_in_url || request.referer.include?("google")
super
goals_path
else
stored_location_for(resource) || request.referer || root_path
end
end