0
我想運行一個簡單的循環來創建多個種子用戶:用色器件用戶播種DB失敗:ActiveRecord的:: RecordInvalid:驗證失敗:電子郵件無效
在seeds.rb:
5.times do
user = User.new(
email: RandomData.random_space_email,
password: 'teatea',
password_confirmation: 'teatea'
)
user.skip_confirmation!
user.save!
end
RandomData.random_space_email:
def self.random_space_email
"#{@@names.sample}@#{@@space_words.sample}.#{@@space_words.sample}"
end
當我運行rake db:reset
我得到這個錯誤:ActiveRecord::RecordInvalid: Validation failed: Email is invalid
但是,如果我將循環設置爲僅運行一次(1.times do
),則所有操作都按預期運行。
任何幫助將是美好的!
嘗試使用'email =(0..8).map {('a'..'z')。to_a [rand(26)]}。加入+「@ yopmail.com」查看一般電子郵件地址。 –
@MayurShah有趣!謝謝! – mtaff
不客氣。 –