Dotol
Dotol

Reputation: 406

Devise Invitable display invited users

I'm using the devise_invitable gem along with Devise but I can't figure out how to show a list of all invited users. I want to list all invited users with their status of accepted/pending.

I have already made a custom Invitations controller (as per the official documentation) that inherits from Devise's controller in which I have a super statement so that it doesn't change functionality but rather adds some below the super. I've scoured issues related to this one and found very few but they use a completely different and unrelated approach. Any input is appreciated~

For example, trying to access @users from invitations/new view throws an undefined method 'each'.

Upvotes: 0

Views: 1714

Answers (1)

kurenn
kurenn

Reputation: 1055

If you have an invitations_controller you can simply add this:

def index
  @users = User.all
end

You don't need to inherit from Devise, just from the ApplicationController. You will be able to access the @users variable, now if you want to separate the results into two separate arrays then:

def index
  @pending_users = User.where(invitation_accepted_at: nil)
  @accepted_users = User.where.not(invitation_accepted_at: nil)
end

And your view you can access the @pending_users as well as @accepted_users

Upvotes: 2

Related Questions