Repository navigation
How To: Require authentication for all pages
Drew Ulmer edited this page May 7, 2013
·
8 revisions
In case your app requires users to be authenticated for all pages and to avoid the "You need to sign in or sign up before continuing." message when trying to access the application root, add this to your routes.rb:
authenticated :user do root :to => 'home#index', :as => :authenticated_root end root :to => redirect('/users/sign_in')
As of Rails 4+, two routes with the same name will raise an exception at app load time. In the above example, it is important to note that the two routes respond to the same URL but they have two different route names (authenticated_root_path and root_path).