如何更新rails控制器

时间:2016-07-26 16:00:04

标签: ruby-on-rails ruby ruby-on-rails-5

我正在使用条带供用户订阅。从那里我收集条纹日期并将其保存在订阅模式。我为我的用户模型创建了枚举,以根据条带订阅ID分配不同的角色。 这是我的用户模型的样子

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

和bellow是我的订阅控制器

   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 test@example.com',
         source: params[:stripeToken],
         email: 'test@example.com'
     )
     # 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)

我如何更新角色以及我做错了什么?

1 个答案:

答案 0 :(得分:1)

您是否尝试过:current_user.role = plan.id

看起来您只是在role()对象上调用curent_user方法。