无法在rails教程中播种数据库
11.2.2
首先我迁移了db(bundle exec rake db:migrate:reset),然后我尝试播种它(捆绑exec rake db:seed),我得到这条消息:
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 ' Tasks: TOP => db:seed
这是我的db/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) users = User.order(:created_at).take(6) 50.times do content = Faker::Lorem.sentence(5) users.each { |user| user.microposts.create!(content: content) } end
试试这个:
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
- 如何在部署到heroku时解决rails中的更新捆绑器警告?
- Ruby(on Rails)语法
- Rails教程(M.Hartl)第3版,第8章,如何通过关闭流氓`rails console`来解锁数据库?
- RSpec测试破坏方法(Rails Tutorial 3.2 Ch.9,Ex.10)
- 为什么carrierwave导致NameError:未初始化的常量Micropost :: PictureUploader错误?
- Rails教程:RSpec测试解耦
- rails generate – “找不到生成器”
- 为什么我的RSpec测试失败,但我的应用程序正在运行?
- 用户注册测试在M.Hartl的Rails教程中失败