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