ruby-on-rails – 未定义的局部变量或方法`current_user’
我正按照
teamtreehouse.com guide构建我的第一个Ruby on Rails应用程序(ruby 2.0.0p353).
我正在使用设计3.2.2 devise并在application.html.erb中我想使用devise的“current_user”来显示登录用户的名称. 这里是我使用“current_user”的代码: <ul class="nav navbar-nav pull-right"> <li><%= link_to current_user.first_name,"#" %></li> <li><%= link_to "Log Out",destroy_user_session_path,method: :delete %></li> </ul> routes.db: Treebook::Application.routes.draw do devise_for :t_busers resources :statuses root to: 'statuses#index' end 但是,在运行我的应用程序时,我总是收到以下错误: undefined local variable or method `current_user' for #<#<Class:0x007f98b1d0edb8>:0x007f98b1cff6d8> 我用其他设计方法得到了同样的错误.如果我已登录或未退出,我会收到错误消息.设计的注册,编辑等似乎工作正常.我试过把“before_filter:authenticate_user!”如设计文档中所示,进入application_controller.rb,但这也不起作用. 为了在视图中使用设计的帮助,我还需要做些什么吗? 解决方法
从你的路线文件,帮助应该是
current_t_buser 从设计文档
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |