0

运行 rake db:reset 后我运行 rake db:populate 并且我收到此错误不知道它来自哪里

rake aborted!
undefined method `+' for 4..5:Range

Tasks: TOP => db:populate
(See full trace by running task with --trace)

在我的任务文件夹中

namespace :db do
  desc " Fill database with sample data"
  task populate: :environment do
     admin = User.create!(name: "Emple User", 
                          email: "exampel@railstuttorial.org",    
                          password: "password",
                          password_confirmation: "password")
  admin.toggle!(:admin)                 
     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   
     users = User.all(limit: 6)
     50.times do
       content = Faker::Lorem.sentence(4..5)
       users.each { |user| user.microposts.create!(content: content) }
       content = nil 
     end             
  end


end
4

1 回答 1

0

Faker::Lorem.sentence您在50.times循环中传递了一个范围。

我不确定您要实现什么,但该方法需要一个整数(您的意思是 4 还是 5?),并且当它尝试在Faker::Lorem代码中添加一些内容时,它会导致该错误。

于 2013-01-22T20:32:17.890 回答