[英]How to skip a landing page
I have a landing page that is like a large scrolling infographic. 我有一个登陆页面,就像一个大型滚动信息图表。 I need to implement a "skip this next time" checkbox so that returning users that authenticate can skip having to see it everytime they visit the site. 我需要实现“跳过下一次”复选框,以便返回的用户进行身份验证可以跳过每次访问站点时都必须看到它。
The landing page is a static page served by the static_controller.rb
: 登录页面是static_controller.rb
提供的静态页面:
def landing
if cookies[:skip_landing]
redirect_to home_url
else
if params[:skip_landing]
cookies.permanent[:skip_landing] = true
end
end
end
This mostly works as I think it should. 这大多数工作正如我认为的那样。 It sets the cookie[:skip_landing]
to true . 它将cookie[:skip_landing]
为true 。 However, when I clear that cookie, I can't get back to the landing page. 但是,当我清除该cookie时,我无法返回登录页面。 I am redirected to the home page, which should only be true if the cookie were set. 我被重定向到主页,只有在设置了cookie时才应该为true。 Somehow, the cookie is being reset 不知何故,cookie被重置
What am I missing? 我错过了什么?
Interesting question. 有趣的问题。 I've debugged for around 10mins and then realised that cookies[:skip_landing]
is actually a String. 我调试了大约10分钟,然后意识到cookies[:skip_landing]
实际上是一个字符串。
So even if you have cookies[:skip_landing] = 'false'
, it if cookies[:skip_landing]
would still be seen as true since only nil
and false
in ruby is false. 所以,即使你有cookies[:skip_landing] = 'false'
, if cookies[:skip_landing]
仍然被视为真,因为红宝石中只有nil
和false
是假的。
You may try this: 你可以试试这个:
if cookies[:skip_landing] == '1'
redirect_to home_url
elsif params[:skip_landing]
cookies.permanent[:skip_landing] = '1'
end
end 结束
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.