ruby on railsでrake db:seedを実行して(facebookのように文章と画像を投稿できるアプリを作っています)ユーザ10人を生成して、13個のインスタとそのインスタの文書に投稿されたコメントを自動生成しようと以下のseedをつくりました。10人のユーザはきちんとできたのですが13個のインスタができていません(それに付随するコメントもです)
おそらく後半部(13.timesより下)がうまく実行されていないようにも思えるのですが・・
何がダメなのでしょうか?
10.times do |n|
email = Faker::Internet.email
password = "password"
User.create!(email: email,
password: password,
password_confirmation: password,
uid: SecureRandom.uuid,
)
end
13.times do |n|
user_id = rand(1..User.last.id)
unless User.find_by(id: user_id) == nil
inst = Inst.new
inst.content = "ほげ内容"
inst.user_id = user_id
inst.save
comment = Comment.new
comment.inst_id = inst.id
comment.content = "ほげコメント"
comment.save
end
end
あなたの回答
tips
プレビュー