いくつかのデータをシードしようとしていますが、ハッシュを受け取るフィールドがあります。私が次のことをするとき
50.times do
Event.create(
name: Faker::Internet.name,
data: Faker::Lorem.words(4),
uri: Faker::Internet.url
)
end
events = Event.all
ハッシュ フィールドであるため、データが配列としてシードされているというエラーが表示されます。これを回避する方法はありますか?
rake aborted!
Mongoid::Errors::InvalidValue:
Problem:
Value of type Array cannot be written to a field of type Hash
Summary:
Tried to set a value of type Array to a field of type Hash
私は次のことを試しました:
data: Faker::Lorem.words(4).to_h
しかし、うまくいかないようです。