2014-02-05 26 views
0

我使用設計爲我的用戶模型。我想,當用戶取消他的帳戶:銷燬用戶(設計)並執行其他任務

Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete %> 

也執行像我的情況下,取消用戶的訂閱條紋一些其他任務。所以我不知道如果我做了什麼是好,但我創造了這個方法到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 

我認爲,甚至不執行此方法,因爲當我取消我的帳戶閃光燈消息是不同的。

我在哪裏錯了?這可能嗎?因爲我有這種感覺,我所做的是錯誤的。

謝謝。

回答

1

您應該鏈接到破壞行動,而不是registration_path

Unhappy? <%= link_to "Cancel my account", user_path(user), :data => { :confirm => "Are you sure?" }, :method => :delete %> 
+0

哦扣......有時候,我沒有看到明顯的解決方案:)謝謝! –