2015-02-06 25 views
1

11.2.2無法在軌教程

第一種子數據庫遷移我DB(捆綁高管耙分貝:遷移:重置),然後我嘗試它的種子(捆綁高管耙分貝:種子),我得到這個消息:

rake aborted! 
SyntaxError: /home/aki/sample_app/db/seeds.rb:25: syntax error, unexpected end-of-input, expecting keyword_end 
/home/aki/.rvm/gems/ruby-2.1.3/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load' 
/home/aki/.rvm/gems/ruby-2.1.3/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `block in load' 
/home/aki/.rvm/gems/ruby-2.1.3/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency' 
/home/aki/.rvm/gems/ruby-2.1.3/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load' 
/home/aki/.rvm/gems/ruby-2.1.3/gems/railties-4.2.0/lib/rails/engine.rb:547:in `load_seed' 
/home/aki/.rvm/gems/ruby-2.1.3/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:250:in `load_seed' 
/home/aki/.rvm/gems/ruby-2.1.3/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:180:in `block (2 levels) in <top (required)>' 
Tasks: TOP => db:seed 

這是我的db/seeds.rb文件:

User.create!(name: "Example User", 
      email: "[email protected]", 
      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) 

users = User.order(:created_at).take(6) 
50.times do 
    content = Faker::Lorem.sentence(5) 
    users.each { |user| user.microposts.create!(content: content) } 
end 
+2

你錯過了99.times塊上的'end' – 2015-02-06 20:59:57

回答

2

試試這個:

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 #This is the missing end and your sytax error 
+0

當我在那裏添加'end'(在我發佈問題之前),我的控制檯一直運行太久,所以我幾次取消了它。現在沒關係。謝謝! – Alek 2015-02-06 21:26:02

+0

@AleksaR很高興它的工作,不客氣! – 2015-02-06 21:59:28