0

我在我的 Rails 4 应用程序中使用 Sorcery 进行身份验证,但我无法让 current_users 方法工作。我不断收到以下错误:

undefined local variable or method `current_users' for #<UsersController:0x007fc7b5a75588>

看法:

Currently active users: <%= current_users_list %>

Application_controller.rb :

class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception
  helper_method :current_users_list

  private
  def not_authenticated
    redirect_to login_url, :alert => "First log in to view this page."
  end

  def current_users_list
    current_users.map {|u| u.email}.join(", ")
  end

end
4

2 回答 2

0

如果您像我一样遵循wiki 指南,那么子模块将自动添加。那么问题是双重的:

  1. 您需要重新启动您的 Rails 服务器
  2. 您需要确保设置了用户名字段或将其更改为电子邮件

current_users.map {|u| u.username}.join(", ")

current_users.map {|u| u.email}.join(", ")

于 2014-04-05T14:50:17.827 回答
0

您可能没有启用活动记录模块。

更改您的初始化程序以包含它:

Rails.application.config.sorcery.submodules = [:activity_logging, whatever_else]
于 2014-03-26T10:14:44.993 回答