authenticate_user!并允许belongs_to关联的设计模型更新参数?

时间:2019-01-11 05:07:37

标签: ruby-on-rails ruby devise

我想允许会员设计模型更新用户设计模型commission参数。

我有一个用户模型:

  belongs_to :affiliate, optional: true

和会员模型:

  has_many :users

然后我为用户创建了一个表格,其中包含会员或管理员可以更新的表格。虽然,我想保留authenticate_user!,但似乎无法正确找出答案

我已经在UsersController中尝试过

private

def make_sure_affiliate_user
  authenticate_user! || current_affiliates.user
end

before_action :authenticate_user!, :only => [:edit, :new, :add_user ]
before_action :make_sure_affiliate_user, :only => [:update]

是否尝试过复数。

我希望会员能够在用户表上更改:commission参数。

如何在方法中创建正确的关联?

例如,我可以找到会员会员的订单:

Order.all.where(seller: current_affiliate.users )

但那还是行不通的。

此外,我如何才能指定联属会员仅出于安全目的而只能更新一个参数?

0 个答案:

没有答案
相关问题