Ruby on rails NoMethodError未定义的方法“stripe_customer_token';
我正在设置从订阅控制器取消订阅,但是在操作中我收到一个无方法错误Ruby on rails NoMethodError未定义的方法“stripe_customer_token';,ruby-on-rails,stripe-payments,Ruby On Rails,Stripe Payments,我正在设置从订阅控制器取消订阅,但是在操作中我收到一个无方法错误未定义的方法'stripe\u customer\u token' 错误指向行@customer=Stripe::customer.retrieve(@user.Stripe\u customer\u token) 订阅控制器: def cancelsubscription @customer = Stripe::Customer.retrieve(current_user.stripe_customer
未定义的方法'stripe\u customer\u token'
错误指向行@customer=Stripe::customer.retrieve(@user.Stripe\u customer\u 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
stripe\u customer\u token
是Subscription
模型中的一个字段。
用户
与订阅关联,且有一个
关联
确保设置@user
的值
改变
@customer = Stripe::Customer.retrieve(@user.stripe_customer_token)
到
在用户模型中是否有名为
stripe\u customer\u token
的字段/方法?您在哪里初始化了@user
?stripe\u customer\u token
在订阅模型中。什么是@user?哪个类的实例?它应该是订阅模型的一个实例。另外,您可以在设置@user value.Ah的地方添加代码吗。我必须将@user添加到其中。让我来做吧。谢谢。@KirtiThorat添加@user=current_user
仍然会产生错误。
@user = ... ## Set the value of @user
@customer = Stripe::Customer.retrieve(@user.subscription.stripe_customer_token)