简体   繁体   English

Rails 4 - 设计 - 管理员批准新用户

[英]Rails 4 - Devise - admin approval of new users

I'm trying to figure out how to follow this devise tutorial to add 'approved' to the user model.我正在尝试弄清楚如何按照此设计教程将“已批准”添加到用户模型中。

https://github.com/plataformatec/devise/wiki/How-To:-Require-admin-to-activate-account-before-sign_in https://github.com/plataformatec/devise/wiki/How-To:-Require-admin-to-activate-account-before-sign_in

I have everything set up as shown in the tutorial, except when I save it all and try to click on the link called:我已经按照教程中所示设置了所有内容,除非我保存所有内容并尝试单击名为的链接:

<%= link_to "Users awaiting approval", :action => "index", :approved => "false" %>

I get an error called:我收到一个错误,称为:

undefined method `find_all_by_approved' for #<Class:0x007fbc5cf34dd0>

It highlights the second line of this users/index action:它突出显示了此用户/索引操作的第二行:

def index
    if params[:approved] == "false"
      @users = User.find_all_by_approved(false)
    else
      @users = User.all
      authorize @users
      end
  end

Does anyone know what else needs to be done (besides whats shown in the tutorial) to get this functionality to work?有谁知道还需要做什么(除了教程中显示的内容)才能使此功能正常工作?

Probably, you had typo issue.可能,你有错字问题。 Below one should give you same results.下面一个应该给你相同的结果。

@users = User.where(approved: false)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM