Rails landing pages
-
28-09-2019 - |
문제
I've decided to put a landing page on my website goldhat.org. I want users to be able to go directly to this page if they are logged in and be directed to a landing page if they aren't logged in. The landing page is currently sitting here. If one clicks on the "browse website" link at the top, it will go to what is currently the home page.
Basically I want the landing page and what is currently the home page to share the "www.goldhat.org" web address. I can see how this is easy enough to do with a logged in? conditional, but what about someone who isn't logged in and browses the site. I only really want the landing page to be displayed once.
Any ideas?
해결책
Use a session variable to keep track of whether a visitor that is not logged in has viewed the landing page or not. Something along the lines of:
def index
if !logged_in? && !session[:visited_welcome_page]
redirect_to welcome_path
else
# Render the main view of goldhat.org
end
end
def welcome
session[:visited_welcome_page] = true
# Render welcome view
end