Reputation:
I use Devise for my users model. I want when a user cancel his account:
Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete %>
to also execute some other tasks like in my case cancel user's Stripe subscription. So i am not sure if what I've done is ok but I created this method into users_controller.rb:
def destroy
@user = current_user
customer = Stripe::Customer.retrieve(@user.stripe_customer_token)
customer.cancel_subscription()
if @user.destroy
flash.alert = "Your subscription and account has been cancelled successfully!"
redirect_to root_path
end
end
I think this method is not even executed as when I cancel my account the flash message is different.
Where am I wrong? Is this possible? Because I have the feeling that what I try to do is wrong.
Thank you.
Upvotes: 0
Views: 95
Reputation: 29349
You should link to the destroy action instead of registration_path
Unhappy? <%= link_to "Cancel my account", user_path(user), :data => { :confirm => "Are you sure?" }, :method => :delete %>
Upvotes: 1