简体   繁体   中英

How do I have two home pages, one for logged in users and one for everyone else, both at the root path?

I have a Pages controller, with an action/view called home. I have set this as the root of the site with

map.root :controller => "pages", :action => "home"

At the moment, I am using this page as part of the logged in user's workflow, thus it is required for the user to be logged in to see it.

But I also need the root path to serve as the landing page for new users, with signup links/promotional stuff etc. Is this a good idea? Should I not be using it the way I am (as part of the logged in user's workflow)? Is the best way to do it just to do a check to see if there's a logged in user, and change the display appropriately?

Thanks for reading.

It's a personal preference, but I'd say the root page should be viewable by non-authenticated users. You could then have a before filter on the root page to redirect to the logged in user's home page if there is a current_user.

You can redirect the user to another action based on their login status. Or you can create two views, and render the appropriate one:
render :template => 'logged_in'

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM