【发布时间】:2019-04-30 18:23:50
【问题描述】:
我正在尝试在用户成功付款后将其角色从“免费”更新为“高级”。
用户.rb
class User < ApplicationRecord
enum role: [:free, :premium]
before_create :assign_default_role
def assign_default_role
self.role ||= :free
end
end
订阅控制器
def create
@user = current_user
@subscription = Subscription.new(subscription_params)
if @subscription.save_with_payment
redirect_to @subscription, :notice => "Thank you for subscribing"
@user.update_attribute(role: premium )
else
render :new
end
end
在尝试让用户付款后,我收到此错误未定义的局部变量或方法 `premium'
【问题讨论】:
标签: ruby-on-rails roles user-roles