Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

507
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda