Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`add_route': Invalid route name, already in use: 'root' (ArgumentError)

Im using rails 4.1.1 and ruby 2.1.1 and am having an issue with devise, namely my routes..I have used this many times before

devise_for :users

get 'pages/index'

# Route to Devise Login Page
  devise_scope :user do
    root to: "devise/sessions#new"
  end

# Directing the user after login
  authenticated :user do
    root :to => 'pages#index'
  end

But i get the error

`add_route': Invalid route name, already in use: 'root'  (ArgumentError)

when trying to start the server.. I can see that root is being used twice, but like i said i have been able to do this in the past.. Is there a way around this

Thanks

like image 832
Richlewis Avatar asked Jun 17 '14 15:06

Richlewis


1 Answers

Found this helpful comment here on stackoverflow

For Rails 4.0 you have to make sure you have unique names for the path helpers, like root to: "dashboard#show", as: :authenticated_root. Otherwise the authenticated root and the normal root route end up having the same name for their path helpers, which Rails 4.0 no longer allows

so I changed my authenticated root to helper like so

 # Directing the user after login
 authenticated :user do
   root :to => 'pages#index', as: :authenticated_root
 end
like image 144
Richlewis Avatar answered Sep 25 '22 08:09

Richlewis