Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

500
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda