geniuskid kanyi geniuskid kanyi - 6 months ago 36
Ruby Question

how to update record in rails controller

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


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',
source: params[:stripeToken],
email: ''
# Save this in your DB and associate with the user;s email
stripe_subscription = customer.subscriptions.create(plan:
@sub = Subscription.create(plan:,
customer: stripe_subscription.customer,
subscriptionenddate: stripe_subscription.current_period_end)
flash[:success] = 'sub created!'
redirect_to root_url
render 'new'

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?


Have you tried: current_user.role = ?

It looks like you are just calling the role() method on the curent_user object.