'Devise Invitable: Return a list of invitation tokens

I'm trying to add a button to my page that exports a list of the invited users with Devise Invitable. I want to include the invitation_tokens in that list. User.where.not(invitation_token: nil) works to return the list of users, but it doesn't show the invitation_token there. User.last.invitation_token does return the invitation_token for that specific user, so I know the information is accessible.

Rather than looping through each invited user to retrieve its invitation_token, is there a way to get ActiveRecord to automatically return the token with a user? For example, User.where.not(invitation_token: nil) currently returns the following:

#<ActiveRecord::Relation [#<User id: 6, email: "[email protected]", created_at: "2022-05-09 11:37:07", updated_at: "2022-05-09 11:37:07"]>



Solution 1:[1]

It looks like there's a security measure in Devise that prevents sensitive information form being shown. Workarounds can be found here: Rails & Devise: devise specific columns not showing up in rails console

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 anotheruser