Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails I18n::MissingTranslationData:缺少翻译:设定数据库种子时出现en.faker错误_Ruby On Rails_Rails I18n_Faker_Bloc.io - Fatal编程技术网

Ruby on rails I18n::MissingTranslationData:缺少翻译:设定数据库种子时出现en.faker错误

Ruby on rails I18n::MissingTranslationData:缺少翻译:设定数据库种子时出现en.faker错误,ruby-on-rails,rails-i18n,faker,bloc.io,Ruby On Rails,Rails I18n,Faker,Bloc.io,我想用Faker为数据库添加种子,问题是我在执行以下操作时出错: rake db:reset 我得到这个信息: rake aborted! I18n::MissingTranslationData: translation missing: en.faker.name.name /Library/Ruby/Gems/2.0.0/gems/i18n-0.7.0/lib/i18n.rb:311:in `handle_exception' /Library/Ruby/Gems/2.0.0/gems/

我想用Faker为数据库添加种子,问题是我在执行以下操作时出错:

rake db:reset
我得到这个信息:

rake aborted!
I18n::MissingTranslationData: translation missing: en.faker.name.name
/Library/Ruby/Gems/2.0.0/gems/i18n-0.7.0/lib/i18n.rb:311:in `handle_exception'
/Library/Ruby/Gems/2.0.0/gems/i18n-0.7.0/lib/i18n.rb:161:in `translate'
/Library/Ruby/Gems/2.0.0/gems/faker-1.4.3/lib/faker.rb:128:in `rescue in translate'
/Library/Ruby/Gems/2.0.0/gems/faker-1.4.3/lib/faker.rb:120:in `translate'
/Library/Ruby/Gems/2.0.0/gems/faker-1.4.3/lib/faker.rb:86:in `fetch'
/Library/Ruby/Gems/2.0.0/gems/faker-1.4.3/lib/faker.rb:99:in `parse'
/Library/Ruby/Gems/2.0.0/gems/faker-1.4.3/lib/faker/name.rb:8:in `name'
/Users/hbendev/code/wikitec/db/seeds.rb:6:in `block in <top (required)>'
/Users/hbendev/code/wikitec/db/seeds.rb:4:in `times'
/Users/hbendev/code/wikitec/db/seeds.rb:4:in `<top (required)>'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `block in load'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
/Library/Ruby/Gems/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:547:in `load_seed'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:250:in `load_seed'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:180:in `block (2 levels) in <top (required)>'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:139:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:setup => db:seed
在我的seeds.rb文件中,
之后需要“faker”
,但没有运气

看起来问题出在Faker本身,因为数据库的创建是正确的,当我执行
rake db:drop db:create db:migrate
时,它会一直工作,直到出现为止,但是当我尝试使用Faker
rake db:seed
rake db:reset
为数据库设置种子时,我得到了错误

我能做什么?提前谢谢

更新-我包括seeds.rb和en.yml文件

seeds.rb:

require 'faker'

# Create Users
5.times do
  user = User.new(
    name: Faker::Name.name,
    email: Faker::Internet.email,
    password: Faker::Lorem.characters(10)
  )
  user.skip_confirmation!
  user.save!
end
users = User.all

# Create Wikis
25.times do
  Wiki.create!(
    title: Faker::Lorem.sentence,
    body: Faker::Lorem.paragraph,
    :private => false,
    user: users.sample
  )
end

# Create Admin account
admin = User.new(
  name: 'Admin User',
  email: 'admin@example.com',
  password: 'helloworld',
  role: 'admin'
  )
admin.skip_confirmation!
admin.save!

# Create Premium account
premium = User.new(
  name: 'Premium User',
  email: 'premium@example.com',
  password: 'helloworld',
  role: 'premium'
  )
premium.skip_confirmation!
premium.save!

# Create Standard account
standard = User.new(
  name: 'Standard User',
  email: 'standard@example.com',
  password: 'helloworld',
  role: 'standard'
  )
standard.skip_confirmation!
standard.save!

puts "Seed finished"
puts "#{Wiki.count} wikis created"
puts "#{User.count} users created"
欧洲货币基金组织:

en:
  hello: "Hello world"

在此处检查I18n伪造者配置信息:

看起来您应该强制使用I18n Faker语言环境,以防在应用程序中使用非标准语言环境

只要将Faker::Config.locale设置为所需的语言环境,Faker就会 照顾好其余的人

这对我有用

在您的
Gemfile
中添加
:require=>false

group :development, :test do
  #gem 'faker', '~> 1.4.3'
  gem 'faker', :require => false
end
手动添加
require“faker”

我也遇到了同样的问题。 有必要将伪造者从

group: development: test do
  gem 'faker'
end
对我来说,它解决了一个问题
祝你好运

在我的例子中,I18n可用的语言环境配置不包括
en

config.i18n.available_locales = %i[de de_en]
我把它恢复到原来的状态

config.i18n.available_locales = %i[de en]

它成功了。

你能发布seed文件吗?你能发布en.yml文件吗?@thesalit我刚包括seed.rb文件。@JoelL我刚包括en.yml文件。
config.i18n.available_locales = %i[de en]