Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Ben Leonard
1,927 PointsBuilding Social Features: Creating the Friendship - Routing Error
I'm getting this error when I make the edit to the routes file:
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/actionpack-4.0.1/lib/action_dispatch/routing/route_set.rb:434:in `add_route':
Invalid route name, already in use: new_user_session' (ArgumentError)
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:
And here's my code:
as :user do
get '/register', to: 'devise/registrations#new', as: :register
get '/login', to: 'devise/sessions#new', as: :login
delete '/logout', to: 'devise/sessions#destroy', as: :logout
end
devise_for :users, skip: [:sessions]
as :user do
get '/login' => 'devise/sessions#new', as: :new_user_session
post '/login' => 'devise/sessions#create', as: :new_user_session
delete '/logout' => 'devise/sessions#destroy', as: :destroy_user_session
end
Cheers
4 Answers

Jon Gjerset
3,816 PointsI've got the same error, using Rails 4.
Did anyone find a solution for this one yet?

Ben Leonard
1,927 PointsI think it's because I'm using Rails 4. I changed the routes to:
as :user do
get '/login' => 'devise/sessions#new', as: :new_user_session
post '/login' => 'devise/sessions#create', as: :create_new_user_session
delete '/logout' => 'devise/sessions#destroy', as: :destroy_user_session
end
But I still don't understand why I'm doing this? Could someone explain why the devise_for :users, skip [:sessions] changes are necessary? Cheers

davidalvarado
7,544 PointsI had the same issue, just realized that post was wrong should be as: :user_session
as :user do
get '/login' => 'devise/sessions#new', as: :new_user_session
post '/login' => 'devise/sessions#create', as: :user_session
delete '/logout' => 'devise/sessions#destroy', as: :destroy_user_session
end
I would also be interested in the reason this needs to be changed.

Seph Cordovano
17,400 PointsUsing Rails 4 and can't find a solution either. Can we get some help here please?