我有一个User 模型和users 表。一个用户可以有很多电话号码,所以我有一个名为 Phone
的单独模型。
我为此使用了这个协会:
模型
User
attr_accessible :id, :name, :screenname,:fullname,:phones_attributes
has_many :phones,:dependent => :destroy
Phone
attr_accessible :phone
belongs to :users
以上代码运行良好。
管理员也想将任何用户的记录复制到 user_temp
和 phone_temp
表中(我有单独的模型名为 UserTemp 和 PhoneTemp).
我该怎么做?
最佳答案
最简单的方法是:
phone_item = Phone.find(x) # Get the phone item you want to copy
# you may have obtained this some other way
PhoneTemp.create(phone_item.attributes) if phone_item
对于用户也是如此。
关于ruby-on-rails - 在 rails 中将一个表记录复制到另一个表记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18786685/