NoMethodError未定义的方法`stripe_customer_token'

时间:2014-03-11 17:23:29

标签: ruby-on-rails stripe-payments

我正在设置取消订阅控制器中的订阅,但是在操作中我收到No Method Error undefined method `stripe_customer_token'

错误指向第@customer = Stripe::Customer.retrieve(@user.stripe_customer_token)

订阅控制器:

     def cancelsubscription
         @customer = Stripe::Customer.retrieve(current_user.stripe_customer_token)
         @customer.cancel_subscription()
         @current_user.subscriptionstatus = false
         current_user.save!
         UserMailer.stripe_cancellation(current_user).deliver
         flash.alert = 'Your subscription has been cancelled successfully!'
         redirect_to edit_user_registration_path
       end
end

1 个答案:

答案 0 :(得分:2)

stripe_customer_tokenSubscription模型中的字段。 User与具有has_one关联的订阅相关联。

确保设置@user

的值

并改变

@customer = Stripe::Customer.retrieve(@user.stripe_customer_token)

@user = ...     ## Set the value of @user
@customer = Stripe::Customer.retrieve(@user.subscription.stripe_customer_token)