I have a custom Devise Session Controler. I need to register the user when Logout, for this I need the current_user helper method.
include Devise::Controllers::Helpers
class Api::UsersController < Devise::SessionsController
def create
super
p current_user # Object user - OK!
end
def destroy
super
puts current_user # nil - I need this
end
end
How do I get current user in the method destroy ?
You could use a rails callback.
include Devise::Controllers::Helpers
class Api::UsersController < Devise::SessionsController
before_destroy: :do_something
def create
super
p current_user # Object user - OK!
end
def destroy
end
def do_something
current_user
end
end
Do whatever you want in the "do_something" method.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.