Tag: faker

Rake aborted使用faker为ruby项目上传图像

我正在关注Ruby on Rails指南并遇到使用gem“Faker”生成虚假内容的问题。 我安装了faker并按照说明将用户和照片填充到我的项目中。 我在lib / tasks / populate.rake中创建了这个文件 LIB /任务/ populate.rake namespace :db do desc “Fill database with sample data” task populate: :environment do 10.times do |n| puts “[DEBUG] creating user #{n+1} of 10” name = Faker::Name.name email = “user-#{n+1}@example.com” password = “password” User.create!( name: name, email: email, password: password, password_confirmation: password) end User.all.each […]

我们应该在Rails工厂中使用Faker吗?

我喜欢Faker ,我在我的seeds.rb使用它seeds.rb一直用真实的数据来填充我的开发环境。 我也刚刚开始使用Factory Girl ,这也节省了大量时间 – 但是当我在网络上搜索代码示例时,我没有看到很多人将两者结合起来的证据。 问:为什么人们不在工厂里使用faker有充分的理由吗? 我的感觉是,通过这样做,我会通过随机播种随机 – 但可预测的 – 数据来增加我的测试的稳健性,这有望增加错误弹出的可能性。 但也许这是不正确的,或者对硬编码工厂没有任何好处,或者我没有看到潜在的陷阱。 是否应该或不应该合并这两颗gem有充分的理由吗?

NameError:未初始化的常量Faker

我试图在Rails 4中为我的数据库运行一个简单的bundle exec rake db:seed。但是,在运行它时,我得到以下输出: ********-C02MGBVJFD57:myapp ***********$ bundle exec rake db:seed Your Gemfile lists the gem factory_girl_rails (>= 0) more than once. You should probably keep only one of them. While it’s not a problem now, it could cause errors if you change the version of just one of them later. rake aborted! NameError: uninitialized […]