Ruby on rails Rails 4,设计-登录重定向路径
我正在尝试在rails 4中制作一个应用程序 我已经尝试在我的应用程序控制器中创建一个后登录路径来重定向用户 当我使用新会话(通过omniauth回调控制器)登录Desive时,我希望进入我的个人资料页面。个人资料#在这种情况下,我想看的就是这个页面。每个用户都有一个配置文件(配置文件属于用户) 如果我从需要身份验证的页面进行身份验证,请求引用器将重定向到该页面 在验证电子邮件的情况下,我仍然会获得完成注册路径(尽管该表单中除提交按钮外的所有表单字段都不会呈现)。如果电子邮件已验证,则完成注册路径不应为重定向路径 相反,我被发送到根路径 有人能看出我做错了什么吗Ruby on rails Rails 4,设计-登录重定向路径,ruby-on-rails,devise,path,Ruby On Rails,Devise,Path,我正在尝试在rails 4中制作一个应用程序 我已经尝试在我的应用程序控制器中创建一个后登录路径来重定向用户 当我使用新会话(通过omniauth回调控制器)登录Desive时,我希望进入我的个人资料页面。个人资料#在这种情况下,我想看的就是这个页面。每个用户都有一个配置文件(配置文件属于用户) 如果我从需要身份验证的页面进行身份验证,请求引用器将重定向到该页面 在验证电子邮件的情况下,我仍然会获得完成注册路径(尽管该表单中除提交按钮外的所有表单字段都不会呈现)。如果电子邮件已验证,则完成注册路
def after_sign_in_path_for(resource)
if !resource.email_verified?
finish_signup_path(resource)
elsif params[:redirect_to].present?
store_location_for(resource, params[:redirect_to])
elsif request.referer == new_session_path(:user)
profile_path(resource.profile) # or whatever the route is for the destination you want
else
stored_location_for(resource) || request.referer || root_path
end
end
def set_redirect_path
@redirect_path = request.path
end
Omniauth回调控制器具有:
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
#sourcey tutorial ------------------
def self.provides_callback_for(provider)
class_eval %Q{
def #{provider}
@user = User.find_for_oauth(env["omniauth.auth"], current_user)
if @user.persisted?
sign_in_and_redirect @user, event: :authentication
else
session["devise.#{provider}_data"] = env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
}
end
[:twitter, :facebook, :linkedin, :google_oauth2].each do |provider|
provides_callback_for provider
end
end
这对我有用。我将概要文件路径重定向放在根路径之前的最后一个选项字符串中,而不是将其作为单独的else语句(我现在认为这与存在请求引用器的登录重定向路径冲突)
def after_sign_in_path_for(resource)
if !resource.email_verified? or !resource.first_name.present? or !resource.last_name.present?
finish_signup_path(resource)
elsif params[:redirect_to].present?
store_location_for(resource, params[:redirect_to])
else
stored_location_for(resource) || request.referer || profile_path(resource.profile) ||root_path
end
end
我在Github上找到了一个简单而有效的解决方案 还声明,为了使上述功能正常工作,您的根路径必须是公共可见的
你能在这里添加你的
omniauth\u callbacks\u controller.rb
文件吗?另外,user.rb
文件我可以看到你已经关注了sourcey教程,请使用designe关注omniauth的wiki:你会明白问题的来源。恐怕这没有什么帮助。我已经尝试设置designe/omniauth三年了。omniauth文档充满了错误和假设。您可以从我为帮助设置这些功能而发布的30多份奖金中看到我概述的问题。如果您能分享您发现的问题,我将不胜感激。我可以理解,首先破解这些问题有点复杂。让我们从头开始。我知道您在是时候想办法了,但他们的方法我已经想出来了,这是一个有点不同的一个,我相信这一次不会花太多时间。让我们加入聊天
def after_sign_in_path_for(resource)
if !resource.email_verified? or !resource.first_name.present? or !resource.last_name.present?
finish_signup_path(resource)
elsif params[:redirect_to].present?
store_location_for(resource, params[:redirect_to])
else
stored_location_for(resource) || request.referer || profile_path(resource.profile) ||root_path
end
end
def after_sign_in_path_for(resource)
stored_location_for(resource) || profile_path
end
before_action :authenticate_user!, except: [:landing]