未初始化的常量 Faker::Date 更新到 rails 5.1

Posted

技术标签:

【中文标题】未初始化的常量 Faker::Date 更新到 rails 5.1【英文标题】:uninitialized constant Faker::Date Updating to rails 5.1 【发布时间】:2017-12-14 18:02:33 【问题描述】:

当我尝试从 rails 5.0 更新到 5.1 时,我有一个工作应用程序。 (我一直在从 4.2 更新到 5.0)

它不再起作用了,运行如下命令:

rails server

产生错误。我不知道如何解决这个问题,也找不到任何信息,这很奇怪,因为它指向的是伪造者的代码,而不是我的。

这是控制台输出

/home/gaston/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.7/lib/bundler/runtime.rb:94:in rescue in block (2 levels) in require': There was an error while trying to load the gem 'faker'. (Bundler::GemRequireError) Gem Load Error is: uninitialized constant Faker::Date Backtrace for gem load error is: /home/gaston/.rvm/gems/ruby-2.3.1/gems/faker-1.8.1/lib/faker/time.rb:2:in ' /home/gaston/.rvm/gems/ruby-2.3.1/gems/faker-1.8.1/lib/faker/time.rb:1:in <top (required)>' /home/gaston/.rvm/gems/ruby-2.3.1/gems/faker-1.8.1/lib/faker.rb:214:in block in ' /home/gaston/.rvm/gems/ruby-2.3.1/gems/faker-1.8.1/lib/faker.rb:214:in each' /home/gaston/.rvm/gems/ruby-2.3.1/gems/faker-1.8.1/lib/faker.rb:214:in ' /home/gaston/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.7/lib/bundler/runtime.rb:91:in require' /home/gaston/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.7/lib/bundler/runtime.rb:91:in block(2 级)在 require' /home/gaston/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.7/lib/bundler/runtime.rb:86:in each' /home/gaston/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.7/lib/bundler/runtime.rb:86:in block in require' /home/gaston/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.7/lib/bundler/runtime.rb:75:in each' /home/gaston/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.7/lib/bundler/runtime.rb:75:in require' /home/gaston/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.7/lib/bundler.rb:106:in require' /home/gaston/Workspace/cloud9workspace/projects/time/config/application.rb:7:in ' /home/gaston/.rvm/gems/ruby-2.3.1/gems/railties-5.1.0/lib/rails/commands/server/server_command.rb:128:in require' /home/gaston/.rvm/gems/ruby-2.3.1/gems/railties-5.1.0/lib/rails/commands/server/server_command.rb:128:in block 正在执行' /home/gaston/.rvm/gems/ruby-2.3.1/gems/railties-5.1.0/lib/rails/commands/server/server_command.rb:125:in tap' /home/gaston/.rvm/gems/ruby-2.3.1/gems/railties-5.1.0/lib/rails/commands/server/server_command.rb:125:in 执行' /home/gaston/.rvm/gems/ruby-2.3.1/gems/thor-0.19.4/lib/thor/command.rb:27:in run' /home/gaston/.rvm/gems/ruby-2.3.1/gems/thor-0.19.4/lib/thor/invocation.rb:126:in invoke_command' /home/gaston/.rvm/gems/ruby-2.3.1/gems/thor-0.19.4/lib/thor.rb:369:in dispatch' /home/gaston/.rvm/gems/ruby-2.3.1/gems/railties-5.1.0/lib/rails/command/base.rb:63:in 执行' /home/gaston/.rvm/gems/ruby-2.3.1/gems/railties-5.1.0/lib/rails/command.rb:44:in invoke' /home/gaston/.rvm/gems/ruby-2.3.1/gems/railties-5.1.0/lib/rails/commands.rb:16:in ' /home/gaston/Workspace/cloud9workspace/projects/time/bin/rails:9:in require' /home/gaston/Workspace/cloud9workspace/projects/time/bin/rails:9:in ' /home/gaston/.rvm/gems/ruby-2.3.1/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in load' /home/gaston/.rvm/gems/ruby-2.3.1/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in call' /home/gaston/.rvm/gems/ruby-2.3.1/gems/spring-2.0.2/lib/spring/client/command.rb:7:in call' /home/gaston/.rvm/gems/ruby-2.3.1/gems/spring-2.0.2/lib/spring/client.rb:30:in run' /home/gaston/.rvm/gems/ruby-2.3.1/gems/spring-2.0.2/bin/spring:49:in <top (required)>' /home/gaston/.rvm/gems/ruby-2.3.1/gems/spring-2.0.2/lib/spring/binstub.rb:31:in load' /home/gaston/.rvm/gems/ruby-2.3.1/gems/spring-2.0.2/lib/spring/binstub.rb:31:in <top (required)>' /home/gaston/Workspace/cloud9workspace/projects/time/bin/spring:13:in require' /home/gaston/Workspace/cloud9workspace/projects/time/bin/spring:13:in &lt;top (required)&gt;' bin/rails:3:inload' bin/rails:3:in <main>' Bundler Error Backtrace: from /home/gaston/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.7/lib/bundler/runtime.rb:90:in block (2 个级别) in require' 来自/home/gaston/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.7/lib/bundler/runtime.rb:86:in each' from /home/gaston/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.7/lib/bundler/runtime.rb:86:in block in require' 来自/home/gaston/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.7/lib/bundler/runtime.rb:75:in each' from /home/gaston/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.7/lib/bundler/runtime.rb:75:in 要求' 来自/home/gaston/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.7/lib/bundler.rb:106:in require' from /home/gaston/Workspace/cloud9workspace/projects/time/config/application.rb:7:in ' 来自/home/gaston/.rvm/gems/ruby-2.3.1/gems/railties-5.1.0/lib/rails/commands/server/server_command.rb:128:in require' from /home/gaston/.rvm/gems/ruby-2.3.1/gems/railties-5.1.0/lib/rails/commands/server/server_command.rb:128:in block 正在执行' 来自/home/gaston/.rvm/gems/ruby-2.3.1/gems/railties-5.1.0/lib/rails/commands/server/server_command.rb:125:in tap' from /home/gaston/.rvm/gems/ruby-2.3.1/gems/railties-5.1.0/lib/rails/commands/server/server_command.rb:125:in 执行' 来自/home/gaston/.rvm/gems/ruby-2.3.1/gems/thor-0.19.4/lib/thor/command.rb:27:in run' from /home/gaston/.rvm/gems/ruby-2.3.1/gems/thor-0.19.4/lib/thor/invocation.rb:126:in invoke_command' 来自/home/gaston/.rvm/gems/ruby-2.3.1/gems/thor-0.19.4/lib/thor.rb:369:in dispatch' from /home/gaston/.rvm/gems/ruby-2.3.1/gems/railties-5.1.0/lib/rails/command/base.rb:63:in 执行' 来自/home/gaston/.rvm/gems/ruby-2.3.1/gems/railties-5.1.0/lib/rails/command.rb:44:in invoke' from /home/gaston/.rvm/gems/ruby-2.3.1/gems/railties-5.1.0/lib/rails/commands.rb:16:in ' 来自 /home/gaston/Workspace/cloud9workspace/projects/time/bin/rails:9:in require' from /home/gaston/Workspace/cloud9workspace/projects/time/bin/rails:9:in ' 来自/home/gaston/.rvm/gems/ruby-2.3.1/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in load' from /home/gaston/.rvm/gems/ruby-2.3.1/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in call' 来自/home/gaston/.rvm/gems/ruby-2.3.1/gems/spring-2.0.2/lib/spring/client/command.rb:7:in call' from /home/gaston/.rvm/gems/ruby-2.3.1/gems/spring-2.0.2/lib/spring/client.rb:30:in run' 来自/home/gaston/.rvm/gems/ruby-2.3.1/gems/spring-2.0.2/bin/spring:49:in <top (required)>' from /home/gaston/.rvm/gems/ruby-2.3.1/gems/spring-2.0.2/lib/spring/binstub.rb:31:in load' 来自/home/gaston/.rvm/gems/ruby-2.3.1/gems/spring-2.0.2/lib/spring/binstub.rb:31:in <top (required)>' from /home/gaston/Workspace/cloud9workspace/projects/time/bin/spring:13:in require' 来自/home/gaston/Workspace/cloud9workspace/projects/time/bin/spring:13:in <top (required)>' from bin/rails:3:inload' 从 bin/rails:3:in `'

这是我的文件: spring.rb

#!/usr/bin/env ruby

# This file loads spring without using Bundler, in order to be fast.
# It gets overwritten when you run the `spring binstub` command.

unless defined?(Spring)
  require 'rubygems'
  require 'bundler'

  if (match = Bundler.default_lockfile.read.match(/^GEM$.*?^    (?:  )*spring \((.*?)\)$.*?^$/m))
    Gem.paths =  'GEM_PATH' => [Bundler.bundle_path.to_s, *Gem.path].uniq.join(Gem.path_separator) 
    gem 'spring', match[1]
    require 'spring/binstub'
  end
end

Faker 已经包含在 gemfile 中,我已经更新到最新版本。 宝石文件

gem 'faker', '~> 1.8', '>= 1.8.1'

这是我的 application.rb,(前 7 行) 应用程序.rb

require File.expand_path('../boot', __FILE__)

require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups) 
...

【问题讨论】:

【参考方案1】:

更新时出现问题。我已经从头开始完成了这个过程,现在它可以工作了。和faker没有关系。

【讨论】:

以上是关于未初始化的常量 Faker::Date 更新到 rails 5.1的主要内容,如果未能解决你的问题,请参考以下文章

未初始化的常量 ActiveRecord::DeleteRestrictionError 仅在部署到 Heroku 时

无法将一个类包含到 Ruby 中的另一个类中:未初始化的常量 (NameError)

警告:更新到 PHP 7.2 后使用未定义的常量 _ - 假定为“_”(这将在 PHP 的未来版本中引发错误)

路由错误未初始化常量用户

未初始化的常量 Delayed::Job

未初始化的常量 ExecJS::Runtimes::RubyRacerRuntime