重定向用户注册 [英] Redirect User to Signup

查看:122
本文介绍了重定向用户注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 before_action:authenticate_user!来检查用户是否登录,但它会将用户发送到登录而不是注册

Using before_action :authenticate_user! to check if user logged in. But it sends users to login instead of signup.

尝试将用户指向注册的不同方法而不是登录,但是在成功注册后不会将用户重新发送回原始页面。

Tried different ways of directing user to signup instead of login, but they do not send the user back to the original page after successful signup.

如何发送用户注册并将用户引导回原始页面?

How can I send a user to signup and direct a user back to the original page afterwards?

尝试:

before_filter :auth_user

def auth_user
  redirect_to new_user_registration_url unless user_signed_in?
end



路线文件



Routes File

Rails.application.routes.draw do
  devise_for :installs
  resources :orders
  resources :products
  devise_for :users

  get 'dashboard' => 'pages#dashboard'
  get 'contact' => 'pages#contact'
  get 'cart' => 'carts#index'

  root 'pages#home'


推荐答案

您正在寻找的是 referer
让你的before_filter工作,你可以覆盖Devise的 after_sign_up_path_for

def after_sign_up_path_for(user)
  request.referer
end






编辑



由于 request.referer 在某种程度上不起作用,我认为您可以使用基于会话的解决方案:


EDIT

Since request.referer is somehow not working, I think you could go with a session-based solution:

def auth_user
  session[:before_sign_up_path] = request.fullpath
  redirect_to new_user_registration_url unless user_signed_in?
end

def after_sign_up_path_for(user)
  session[:before_sign_up_path]
end

这篇关于重定向用户注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆