Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

496
Views
devise gem allows you to have multiple models signed in at the same time what that mean?

I am new to Rails and I came across this devise gem can you tell what this line means "devise gem allows you to have multiple models signed"?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Devise is built on top of the Warden gem which is the part that actually does the grunt work of authenticating users and storing the claims in the session.

Warden accepts a scope argument both when storing users in the session and retrieving them. An very simplefied example of the concept is that:

# This code won't actually run as Warden is used as part of the 
# rack stack when dealing with HTTP requests
warden = env['warden']
admin = Admin.create!(email: 'user@example.com', password: 'p4ssword')
user = User.create!(email: 'user@example.com', password: 'p4ssword')

warden.set_user(admin, scope: :admin)
warden.set_user(user, scope: :user)

warden.authenticate(:password, :admin).user == admin 
warden.authenticate(:password, :user).user == user

Whats happening when you call warden.set_user(admin, scope: :admin) is that its saving the id of the record into the session and using the scope as part of the key so that you can store different ids for different scopes. Thus having "different users signed in at the same time".

Devise actually sets the Warden scopes based on the arguments passed to devise_for in your routes file. If you call devise_for :users then the scope is :user.

This isn't really a feature that you you need to use or know about as a beginner since you're just using a single scope most of the time anyways.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!