Using Multiple User Classes
View Live Multi-User Demos
This gem supports the use of multiple user models. One possible use case is to authenticate visitors using a model called User
, and to authenticate administrators with a model called Admin
. Take the following steps to add another authentication model to your app:
Run the install generator for the new model.
This will create the
Admin
model and define the model's authentication routes with the base path/admin_auth
.Configure any
Admin
restricted controllers. Controllers will now have access to the methods described here:before_action :authenticate_admin!
current_admin
admin_signed_in?
Group access
It is also possible to control access to multiple user types at the same time using groups. The following example shows how to limit controller access to both User
and Admin
users.
Example: group authentication
In the above example, the following methods will be available (in addition to current_user
, current_admin
, etc.):
before_action: :authenticate_member!
current_member
member_signed_in?
Last updated