注册后基于导航的重定向 [英] Navigation-based redirections after sign up

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

问题描述

我的网站允许用户自由浏览直至需要登录才能继续使用该服务(点按注册"按钮并完成注册过程).

My website allows users to browse freely up to the point where they need to be signed in to continue using the service (hitting the "sign up" button and going through the registration process).

用户注册后,我想将他们重定向到他们正在浏览的最后一个有趣的页面:它可能是单击注册"按钮之前的页面,或更复杂的页面.例如,假设用户浏览核心"内容页面,然后转到"about_us"页面,然后尝试注册,我宁愿将这些用户重定向到核心"内容页面.

Once the users sign up, I want to redirect them to the last interesting page they were browsing : it might be the page just before clicking the sign-up button, or something more complex. For instance suppose the user browses a "core" content page, then goes to the "about_us" page, then tries to sign up, I'd rather redirect those users to the "core" content page.

我想知道什么是最好的方法

I am wondering what's the best way to do that

  • 隐藏的参数形式?听起来很讨厌在表单中一直跟踪此参数(并在出现错误等情况时保留它).
  • 基于会话的信息(某种智能引荐来源网址"网址)
  • 页面访问(例如,使用Ahoy.js)

最后一个相关页面的跟踪"位置和时间是什么时候?在控制器中?在视图中为JS代码?

And where/when to do this "tracking" of the last relevant page ? In the controller ? in the view as JS code ?

是否有做类似这样的提示?

Any tips to do something like this ?

推荐答案

通过隐藏的表单字段和会话都可以带来好处.在控制器中使用会话是最简单的跟踪开发情况的方法,但是,如果用户打开了多个选项卡,则如果它们在两个选项卡之间跳转,可能会导致页面流动异常.在这里,隐藏的表单域效果更好,但维护起来却很烦人.我倾向于使用session方法,并在控制器操作中执行以下操作:

Both via hidden form fields and sessions have benefits. Using sessions in the controller would be the simplest for you to keep track of as far as development goes however if the user has multiple tabs open it could lead to an odd page flow if they jump between tabs. This is where hidden form fields work out a bit better but are more annoying to maintain. I tend to go with the sessions method and do something like the following in a controller action:

#This will store the page they're coming from to get to this action.
session[:interesting_page] = request.env["HTTP_REFERER"] || root_path

#Or store the current interesting page within the interesting page's controller action
 session[:interesting_page] = request.original_url

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

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