Reputation: 89
am using stripe for users to subscribe. from there i collected the stripe date and save it in subscription mode. i created enum for my user model to assign different roles base on the stripe subscription id. here is how my user model looks like
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
and bellow is my subscription controller
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
when it reach to update the role i get
ArgumentError: wrong number of arguments (1 for 0)
how can i update the role and what am i doing wrong?
Upvotes: 0
Views: 635
Reputation: 6404
Have you tried: current_user.role = plan.id
?
It looks like you are just calling the role()
method on the curent_user
object.
Upvotes: 1