Search code examples
ruby-on-railsdevise

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

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?


Solution

  • Probably, you had typo issue. Below one should give you same results.

    @users = User.where(approved: false)