为什么这个db/seeds.db创建了29200条微博记录?这比预期的要多得多。 RoR Hartl 教程 11.2

Why is this db/seeds.db creating 29200 microposts records? This is way more than expected. RoR Hartl Tutorial 11.2

好的,所以我一直在努力完成我们都喜欢的美丽的 Hartl 教程 - 我被困在一个特定的问题上。第 11.2 章,最后 - 我们刚刚为基本用户发布数据构建了种子和迁移,但他和我得到了不同的结果。

我的 db/seeds.db 中有以下内容:

users = User.order(:created_at).take(6)
50.times do
  content = Faker::Lorem.sentence(5)
  users.each { |user| user.microposts.create!(content: content) }
  end

我会运行一个rake:reset,它会生成一个table,总共有100个用户和29200条微博。这个数字显然太高了。我完全不明白发生了什么,我在哪里可以找到更多调试信息?

这是我当前的分支回购:

https://github.com/kfrz/sample_app/tree/user-microposts

感谢您的帮助!

你的

users = User.order(:created_at).take(6)
50.times do
  content = Faker::Lorem.sentence(5)
  users.each { |user| user.microposts.create!(content: content) }
end

在您的 99.times do |n| ... end 中,只需将结尾从文件末尾移至第 28 行。