【发布时间】:2013-05-06 20:32:49
【问题描述】:
如果我有一个关联 has_many :articles 和 belongs_to :user 的用户和文章模型,我会编写 user.articles.new 来创建一个具有正确 user_id 的新文章对象。
所以我的问题是关于一个具有许多 belongs_to 关系的模型:
class Ownership < ActiveRecord::Base
attr_accessible :right_read, :right_create, :right_update, :right_delete
belongs_to :element
belongs_to :user
belongs_to :ownership_type
end
有没有一种解决方案来创建具有 3 个 ID 已完成的对象所有权(element_id、user_id、ownership_type_id)?
并且在 "attr_accessible" 中写入此 ID 是否危险?
谢谢。
【问题讨论】:
标签: ruby-on-rails model associations