0
上午使用stripe供用户订阅。从那里我收集条纹日期并保存在订阅模式。我为我的用户模型创建枚举以基于条带订阅ID分配不同的角色。 这里是我的用户模型看起来像如何更新记录在rails控制器
class User < ApplicationRecord
enum role: [:user, :gold, :platinum, :diamond ]
has_one :subscription
has_one :shipping
extend FriendlyId
friendly_id :firstname, use: [:slugged, :finders]
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
和波纹管是我的用户控制器
def subscription_checkout
user = current_user
plan_id = params[:plan_id]
plan = Stripe::Plan.retrieve(plan_id)
# This should be created on signup.
customer = Stripe::Customer.create(
description: 'Customer for [email protected]',
source: params[:stripeToken],
email: '[email protected]'
)
# Save this in your DB and associate with the user;s email
stripe_subscription = customer.subscriptions.create(plan: plan.id)
@sub = Subscription.create(plan: stripe_subscription.plan.name,
stripeid: stripe_subscription.id,
user_id: current_user.id,
customer: stripe_subscription.customer,
subscriptionenddate: stripe_subscription.current_period_end)
if @sub.save
current_user.role plan.id
current_user.save
flash[:success] = 'sub created!'
redirect_to root_url
else
render 'new'
end
end
,当它达到更新的角色我得到
ArgumentError: wrong number of arguments (1 for 0)
我怎么可以更新角色和我做错了什么?
工作。现在我得到'未定义的方法'钻石?'对于#用户,即使你在我的rails控制台中返回'user.diamond? => true# –
你的周边代码在哪里?通过在抛出错误之前放置调试器或者您刚打开IRB,您是否跳入了控制台? – arjabbar