Is it OK to put custom logic in routes.rb?
For example:
unless current_user
root :to => anonymous_page
else
root :to => logged_in_page
end
You can put custom logic into routes... but as avenger suggested - "current_user" won't work due to when the routes file is loaded. We sometimes use logic in our routefile (eg setting up routes that are only available if RAILS_ENV == 'development').
What you probably want is a before_filter on "anonymous_page" eg:
before_filter :redirect_if_logged_in, :only => :anonymous_page
def redirect_if_logged_in
redirect_to logged_in_page if current_user.present?
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With