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
:
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 . However, when I clear that cookie, I can't get back to the landing page. I am redirected to the home page, which should only be true if the cookie were set. Somehow, the cookie is being reset
What am I missing?
Interesting question. I've debugged for around 10mins and then realised that cookies[:skip_landing]
is actually a String.
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.
You may try this:
if cookies[:skip_landing] == '1'
redirect_to home_url
elsif params[:skip_landing]
cookies.permanent[:skip_landing] = '1'
end
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.