rake db:尝试为多个表种子时抛出种子错误

时间:2016-07-31 05:27:38

标签: ruby-on-rails ruby

我正在尝试使用一个用于填充两个表的文件来运行rake db:seed

User.destroy_all
Profile.destroy_all

User.create! [
  { username: "Fiorina",  password_digest: "xxx" },
  { username: "Trump", password_digest: "yyy" },
  { username: "Carson", password_digest: "zzz" },
  { username: "Clinton", password_digest: "aaa" }
]

Profile.create! [
  { gender: "f", birth_year: "1954", first_name: "Carly", last_name: "Fiorina" }
  { gender: "m", birth_year: "1946", first_name: "Donald", last_name: "Trump" }
  { gender: "m", birth_year: "1951", first_name: "Ben", last_name: "Carson" }
  { gender: "f", birth_year: "1947", first_name: "Hillary", last_name: "Clinton" }
]

如果我只运行User.create!部分就行了。但是,添加Profile.create!部分会引发错误:

rake aborted!
SyntaxError: /Users/msnyder/bin/JHRoR/scratch/todolists/db/seeds.rb:22: syntax error, unexpected {, expecting ']'
  { gender: "m", birth_year: "19...
   ^
/Users/msnyder/bin/JHRoR/scratch/todolists/db/seeds.rb:25: syntax error, unexpected ']', expecting end-of-input

我已经仔细检查过并且所有括号/括号都匹配了。据我所知,这应该没有任何理由失败。

1 个答案:

答案 0 :(得分:3)

您错过了逗号,

Profile.create! [
  { gender: "f", birth_year: "1954", first_name: "Carly", last_name: "Fiorina" },
  { gender: "m", birth_year: "1946", first_name: "Donald", last_name: "Trump" },
  { gender: "m", birth_year: "1951", first_name: "Ben", last_name: "Carson" },
  { gender: "f", birth_year: "1947", first_name: "Hillary", last_name: "Clinton" }
]