我正在使用 Mike Hartl 的 Rails 教程,尝试执行以下命令:
$ bundle exec rake db:reset
$ bundle exec rake db:populate
$ bundle exec rake test:prepare
我得到了错误:
sample_app/lib/tasks/sample_data.rake:25: syntax error, unexpected end-of-input, expecting keyword_end
end
如果我把lib/tasks/sample_data.rake 文件的代码放在我的代码上,我想我搞混了。
这是代码:
namespace :db do
desc "Fill database with sample data"
task populate: :environment do
admin = User.create!(name: "Example User",
email: "example@railstutorial.org",
password: "foobar",
password_confirmation: "foobar",
admin: true)
users = User.all(limit: 6)
50.times do
content = Faker::Lorem.sentence(5)
users.each { |user| user.microposts.create!(content: content) }
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)
end
end
end
我有点搞混了,我不擅长 Ruby 代码。有谁知道问题是什么?