First I tried to access the session variable in the routes.rb file and put a simple if statement. If the user is logged in, go to the input element # index else, go to the index # of the site. However, route.rb does not seem to have access to session variables. I have a [: user_id] session and you can use it to confirm the login status. Is it better to set the page that was logged out as the home page in route.rb, and then redirect to this controller if the user has registered or is there a better way that I donβt know about?
Here is what I did in the controller for the home page with the user disabled.
def index if User.find_by_id(session[:user_id]) redirect_to entry_url end end
It works great, but not sure if there are any problems with this or the best way. Any thoughts would be appreciated.
source share