我正在设置取消订阅控制器中的订阅,但是在操作中我收到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
答案 0 :(得分:2)
stripe_customer_token
是Subscription
模型中的字段。
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)