How to log out all members?

This should be enough to log out all users, with the possibility of exempting some users:

protected_users = ["system", "codinghorror"] # do not process these users

# get all users that should be logged out
affected_users = User.all.select { |u| !(protected_users.include? u.username) }

affected_users.each { |u|
        u.user_auth_tokens.destroy_all
        u.logged_out
};

This needs to be run within Rails – pasting it into a rails console (./launcher enter app, rails c) should be enough.

Better safe than sorry: Always have a backup ready before going near the Rails console.

4 Likes