RoutingError uninitialized constant

落爺英雄遲暮 提交于 2019-12-01 11:18:19

问题


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.


回答1:


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"}



来源:https://stackoverflow.com/questions/6912542/routingerror-uninitialized-constant

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!