Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在我的本地主机上运行了一个 Rails 应用程序,其中包含大约 10 个帖子,包括图片。无论如何,我只需将这 10 个帖子乘以 100 即可填充?
您可以.dup为此使用:
.dup
posts = Post.all.to_a 9.times do posts.each do |post| post.dup.save end end
.to_a将确保立即获取所有记录,因此添加新记录不会造成任何问题。
.to_a