如何从Rails控制台注销devise用户?

问题描述:

我的设计用户是"database_authenticatable"和"token_authenticatable".我尝试从控制台中删除该用户的数据库中的"authentication_token"字段,但他们似乎仍然能够使用其现有的身份验证令牌.完全删除用户是可行的,但是我不想走那么远.

My devise users are "database_authenticatable" and "token_authenticatable". I've tried deleting the "authentication_token" field in the database for that user from the console, but they still seem to be able to use their existing auth token. Deleting the user entirely works, but I don't want to go that far.

为清楚起见.我想使用导轨控制台登出用户.即先运行rails console,然后运行一些命令.

for clarity. I want to use the rails console to sign out a user. i.e. run rails console and then some command.

Devise提供了辅助方法来完成这些操作.

Devise provide helper methods to do these things.

user = User.find(params[:id])
sign_in user
sign_out user

希望这会有所帮助.