0
我试图确保我的Rails应用程序安全地建立关联,我不知道我应该如何处理这种情况,我有通过另一个模型本质上“拥有”的模型。安全地建设模型协会
一个例子是我是一个拥有十几岁女儿的父亲。他们拥有一些苹果产品。产品在技术上属于他们,但我付出了一切 - 我拥有它。
此外,我不希望陌生人只给女儿新的苹果产品。
该代码,这看起来像:
class Father
has_many :teenage_daughters
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
class TeenageDaughter
belongs_to :father
accepts_nested_attributes_for :apple_products,
reject_if: :all_blank,
allow_destroy: true # oh yeah
end
class AppleProduct
belongs_to :teenage_daughter
# Should i be doing something like this?
# belongs_to :father
end
我的问题是:
我应该BACK加入belongs_to
关系到父亲的AppleProduct
内,不知何故,每当我创建AppleProduct
的I设置current_user
?
我担心出错,并以某种方式允许制作的请求,这将允许人们关联/取消关联行与不属于他们的用户帐户。