RoutingError 未初始化的常量 [英] RoutingError uninitialized constant

查看:25
本文介绍了RoutingError 未初始化的常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序中使用 token_authenticable(使用 Devise).

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

使用这个 答案 我在文件 app/controllers/users_sessions_controller.rb 中添加了 class Users::SessionsController(文件位置是否正确?).

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

为了在数据库中生成 authentication_token,我添加了 current_user.reset_authentication_token! 作为 create 方法的第四行.

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

使用 设计文档 中的配置控制器"部分,我添加了行 devise_for :users,:控制器 =>{:sessions =>用户/会话"} 到我的路线.

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

我也有文件 app/views/users/session/new.html.erb.

现在,当我尝试在浏览器中登录或注销时,出现Routing Error uninitialized constant Users.

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.

推荐答案

如果你想要你的控制器名为 Users::SessionsController 那么它需要在 app/controllers/users/sessions_controller.rb

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 

位于app/controllers/user_sessions_controller.rb,路由为:devise_for :users, :controllers =>{:sessions =>user_sessions"}

这篇关于RoutingError 未初始化的常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆