2013-09-27 55 views
0

我使用麥克哈特爾的Rails的教程,嘗試做以下命令:在哈特爾教程10.20,不能「耙分貝:」

$ 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: "[email protected]", 
         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代碼。有誰知道問題是什麼?

回答

0

50.times do塊沒有end

它應該是:

50.times do 
    content = Faker::Lorem.sentence(5) 
    users.each { |user| user.microposts.create!(content: content) } 
end 
1

有一個「終點」,在書中給出的例子失蹤。它需要兩個「結束」命令,而不是像已經發布的那樣!耙子需要很長時間,所以期望不得不等待一段時間。