NameError:未初始化的常量 Faker [英] NameError: uninitialized constant Faker
本文介绍了NameError:未初始化的常量 Faker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 Rails 4 中为我的数据库运行一个简单的 bundle exec rake db:seed.但是,在运行它时,我得到以下输出:
I am trying to run a simple bundle exec rake db:seed for my database in Rails 4. However, when running it, I get the following output:
********-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 constant Faker
/Users/**********/workspace/myapp/db/seeds.rb:16:in `block in <top (required)>'
/Users/**********/workspace/myapp/db/seeds.rb:15:in `times'
/Users/**********/workspace/myapp/db/seeds.rb:15:in `<top (required)>'
/Users/**********/.rvm/gems/ruby-2.1.2@myapp/gems/railties-4.1.4/lib/rails/engine.rb:543:in `load_seed'
/Users/**********/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/tasks/database_tasks.rb:184:in `load_seed'
/Users/**********/.rvm/gems/ruby-2.1.2@myapp/gems/activerecord-4.1.4/lib/active_record/railties/databases.rake:173:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:seed
(See full trace by running task with --trace)
这是我的seeds.rb文件:
Here is my seeds.rb file:
User.create!(
name: "Example User",
email: "example@railstutorial.org",
password: "foobar",
password_confirmation: "foobar",
admin: true
)
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
第 16 行是:
name = Faker::Name.name
任何想法为什么我会收到此错误?谢谢你.
Any ideas why I am getting this error? Thank you.
推荐答案
刚刚遇到类似问题 - 我正在运行
Just faced similar issue - I was running
rails g model model_name
并得到错误:
uninitialized constant Faker (NameError)
问题是由于我将 gem 添加到 test
组.
Problem was due to fact, that I had gem added to test
group.
放入development
和test
组解决问题:
group :development, :test do
# ...
gem 'faker'
# ...
end
这篇关于NameError:未初始化的常量 Faker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文