8

I'm using devise in my ruby-on-rails app. I have a User class and an AdminUser class using devise. In my admin panel I would like to logout all Users but not AdminUsers.

MIkeO
  • 83
  • 1
  • 1
  • 3

4 Answers4

17

The best way to do this is to use the scope-level sign out methods. So, if you want to sign out all users (User class), then you would do this.

sign_out :user
Josh
  • 5,631
  • 1
  • 28
  • 54
munchbit
  • 531
  • 5
  • 10
15

Very late, but the answer could be something like this

for user in User.all
  sign_out user
end
dumP
  • 771
  • 8
  • 17
4

As someone said here, the simplest way to do this is to change the rails secret token.

Community
  • 1
  • 1
hrdwdmrbl
  • 4,814
  • 2
  • 32
  • 41
  • This is a great answer, thanks for posting it here; even though it doesn't actually answer the question, it was exactly what I was looking for. – Dagmar Oct 30 '19 at 08:27
-2
@users = User.all
@users.log_out

and

def log_out
  # depending on how you store the user's token, just delete it from the database
end

Assuming you are using database authentication.

CamelCamelCamel
  • 5,200
  • 8
  • 61
  • 93