1
私のデータベースに偽のデータをシードしようとしています。私は各プロスペクトを1人のユーザに所属させたい。私のシードはユーザーを作成しますが、プロスペクトを作成することはできません。理由はわかりません。ループにhas_oneが失敗したループをシードします
User.destroy_all
Prospect.destroy_all
50.times do
u = User.new
u.email = Faker::Internet.email
u.password = "password"
u.first_name = Faker::Name.first_name
u.last_name = Faker::Name.last_name
u.save
end
users = User.all
puts users
users.each do |user|
p = Prospect.new
p.id = user.id
p.parent_first_name = user.first_name
p.parent_last_name = user.last_name
p.student_first_name = Faker::Name.first_name
p.save
end
はここ
# prospect.rb
class Prospect < ApplicationRecord
belongs_to :user
def full_parent_name
name = "#{parent_first_name.capitalize} #{parent_last_name.capitalize}"
end
end
# user.rb
class User < ApplicationRecord
has_one :prospect
... lots of devise and Oauth stuff
end
マイプット文がUser.allが50人のユーザーが私は私の問題はbelongs_to
を作成しようとしていることを考える発見されていることを示して私のユーザーと展望モデルだとhas_one
が問題です。私はそれを別の方法で扱うべきですか?
ありがとうございました。これはまさに私の問題でした。 – aisflat439