【问题标题】:Rails devise errorRails 设计错误
【发布时间】:2016-03-18 00:45:33
【问题描述】:

我正在使用设计进行注册。但即使在登录 current_user 后返回 nil。

class Admins::DashboardController < ApplicationController

before_action :authenticate_user!

def show   
  @title="Admin Dashboard | eazy coach"
  logger.info current_user.specific.inspect
end

end

错误:NoMethodError(nil:NilClass 的未定义方法“特定”):

【问题讨论】:

  • 也许你的意思是current_admin,如果它是控制器(class Admins::DashboardController)?
  • 实际上我在管理模型中使用acts_as :user 这就是为什么我添加了current_user。即使我检查了current_admin 也不起作用
  • 您能否检查一下您的 user_signed_in?admin_signed_in? 返回什么?
  • 两者都返回 false
  • 你在用acts_as_user gem吗?

标签: ruby-on-rails devise


【解决方案1】:

我猜你在路由文件中使用了namespace :admins

对于这种情况,您需要使用current_admins_usercurrent_admins_admin 访问用户

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-04
    • 2012-06-13
    • 2016-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多