Heroku运行rake db:seed给出了期望的keyword_end

时间:2015-04-30 14:56:23

标签: ruby-on-rails heroku railstutorial.org

我正在做hartle教程的第11章。 在本章的最后我跑了

heroku run rake db:seed

我收到了这个错误:

rake aborted!
SyntaxError: /app/db/seeds.rb:23: syntax error, unexpected end-of-input, expecting keyword_end

这是我的seeds.rb文件:

User.create!(name:  "Example User",
             email: "example@railstutorial.org",
             password:              "foobar",
             password_confirmation: "foobar",
             admin:     true,
             activated: true,
             activated_at: Time.zone.now)

99.times do |n|
  name  = Faker::Name.name
  email = "example-#{n+1}@railstutorial.org"
  password = "password"
  User.create!(name:  name,
              email: email,
              password:              password,
              password_confirmation: password,
              activated: true,
              activated_at: Time.zone.now)
end
users = User.order(:created_at).take(6)
50.times do
  content = Faker::Lorem.sentence(5)
  users.each { |user| user.microposts.create!(content: content) }
end

到目前为止,我对seed.db没有任何问题!

3 个答案:

答案 0 :(得分:2)

"期望的keyword_end"错误表示您在指定的文件中有语法错误。你会看到很多,特别是在你的测试套件中;得到舒适。

使用细齿梳子浏览文件,并在心理上将每个{}和每个do及其end匹配。通常你会发现其中一个不匹配。

如果找不到匹配项,请注释掉整个种子文件并再次运行rake db:seed。不应出现错误。然后逐步取消注释文件的每个部分,直到找出错误的来源。

这很乏味但很有效。

答案 1 :(得分:0)

我遇到了类似问题

class Tag< ApplicationRecord ::基地     has_many:目的地 结束 端

我的模型中有Double“end end”...我删除了一个“end”并且问题得到了解决

答案 2 :(得分:0)

只需在终端中运行文件,您就应该获得足够的信息来查找旧的unexpected end-of-input语法错误。如果指定-w-选项,还将向您显示其他警告,这些警告通常包含您需要的相关提示。

以您为例:在终端中运行此命令(从项目的根目录):

ruby -w db/seeds.rb

现在,您应该获得一个输出,详细说明seeds.rb中的语法错误,并带有行号(以及其他警告和错误,如果有的话),例如像这样:

db/seeds.rb:19: warning: mismatched indentations at 'end' with 'unless' at 12
db/seeds.rb:25: syntax error, unexpected end-of-input, expecting keyword_end
...
...
相关问题