我希望每个用户在 item_templates 表中都有一组记录开始。然后,在 items 表中,我有 user_id 和每个项目。所以,基本上架构看起来像;
item_templates 表:
- 商品代码
- 商品名称
- ...一堆其他属性
项目表:
- 用户 ID
- 商品代码
- 商品名称
- ...一堆其他属性
每次创建新用户时,我都想在项目表中复制该用户的模板中的项目。有没有简单的方法可以避免编码从 item_templates 复制到项目的所有属性?
最佳答案
item.update_attributes(template.attributes)
关于ruby-on-rails-3 - 轨道 3 : copy attributes and values from one template model to a different model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10562883/