Godzilla74 Godzilla74 - 5 days ago 5
Ruby Question

Sign user out in rails controller

I've created functionality to allow a user to delete their account from my app, that works. However, at the end, I'm trying to automatically log the user OUT which would send them back to the sign in page.

I've tried various things which I thought would work, but my controller is throwing an error saying that I don't have the view in place for the Controller method:


Missing template subscriptions/cancel_subscription


def cancel_subscription
...a bunch of code that clears out the user's info
redirect_to destroy_user_session_path
end


I'm using
Devise
, so the routes are default:

new_user_session GET /login(.:format) devise/sessions#new
user_session POST /login(.:format) devise/sessions#create
destroy_user_session GET /logout(.:format) devise/sessions#destroy


How do I go about automatically logging the user out since they don't actually have any account data anymore?

Answer
def cancel_subscription
  #code to cancel
  sign_out current_user
  redirect_to new_user_session_path
end

inside cancel_subscription