Like the title says, i would like to change the route depending on if there is a user logged in or not, similarly to facebook. Is this possible?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You don’t change the route, you just add a
:before_filterin your controller. There’s a few ways to do it, but a simple example is pretend your root points athomeController#main. On top of the controller you have something likeAnd then in your ApplicationController you write a method like
Which will check your session variable for a user and redirect to their profile if it exists, if not, then it will render your main method normally.
More information and examples here.