gnycl gnycl - 5 months ago 103
Ruby Question

Rake seed without validations failing

I'm trying to populate my database with seed data using

rake db:seed
but for some reason I keep getting this error. Note, I need to bypass validations checks.

user =[
{id: 6, email: ""},
{id: 7, email: ""}
])!(validate: false)

Error that I keep getting:

$ bundle exec rake db:seed RAILS_ENV=test
rake aborted!
ArgumentError: When assigning attributes, you must pass a hash as an argument.

Any guidance on why this is happening and how to fix it?


You are passing an array of hashes to the new method of User model. You need to loop on each of these hashes instead:

  {id: 6, email: ""},
  {id: 7, email: ""}
].each do |user_attributes|
  user =!(validate: false)

I don't think you can overwrite the id attribute though.