未初始化的常量 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:ineach' /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:inrequire' /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:ineach' /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:ineach' /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:inrequire' /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:inrequire' /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:intap' /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:inrun' /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:indispatch' /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:ininvoke' /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:inrequire' /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:inload' /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:incall' /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<top (required)>' bin/rails:3:in
load' 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:ineach' 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:ineach' 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:inrequire' 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:inrequire' 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:intap' 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:inrun' 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:indispatch' 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:ininvoke' 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:inrequire' 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:inload' 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:incall' 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:in
load' 从 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)