Create routes for authenticated users and not on rails 4

1

I would like to create two root routes, one for authenticated users and one for non-authenticated users; for this I use devise , I tried the following code but it gives me an error.

Error

  

Invalid route name, already in use: 'root' You may have defined two   routes with the same name using the :as option, or you may be   overriding a route already defined by a resource with the same naming.   For the latter, you can restrict the routes created with resources   as explained here:    link

routes.rb

Rails.application.routes.draw do
  devise_for :users

  authenticated :user do
    root 'main#home'
  end

  unauthenticated :user do
    root 'main#unregistered'
  end
end

main_controller

class MainController < ApplicationController
 def home
 end

 def unregistered
 end
end
    
asked by denethor 25.09.2016 в 08:00
source

1 answer

0

I think the problem is because both root that you defined, by not specifying an alias, are left with the same. Try to put:

authenticated :user do
    root 'main#home', as: :authenticated_root
end

unauthenticated :user do
    root 'main#unregistered', as: :unauthenticated_root
end
    
answered by 26.09.2016 в 06:06