Mateusz
Mateusz

Reputation: 1197

RoutingError uninitialized constant

I want to use token_authenticatable in my application (using Devise).

Using this answer I added class Users::SessionsController in file app/controllers/users_sessions_controller.rb (is file location correct?).

To generate authentication_token in database I added line current_user.reset_authentication_token! as fourth line of create method.

Using "Configuring Controllers" section from devise docimentation I added line devise_for :users, :controllers => {:sessions => "users/sessions"} to my routes.

I also have file app/views/users/session/new.html.erb.

Now when I try to log in or log out in browser, I get Routing Error uninitialized constant Users.

I have no idea what happens. I think I named controller class wrong, or placed it incorrectly, but don't know for sure.

Upvotes: 1

Views: 3603

Answers (1)

Kyle d'Oliveira
Kyle d'Oliveira

Reputation: 6382

If you want your controller named Users::SessionsController then it need to be in app/controllers/users/sessions_controller.rb

If you don't want nested folders for your controllers you could also do

class UserSessionsController 

located at app/controllers/user_sessions_controller.rb with the routes being: devise_for :users, :controllers => {:sessions => "user_sessions"}

Upvotes: 3

Related Questions