Ruby PUMA错误:"无法加载应用程序:NameError:未初始化的常量Service :: Resolv"

时间:2017-03-23 04:57:44

标签: ruby-on-rails puma resolv

使用Windows 10E ruby 2.3.3p222(2016-11-21修订版56859)[i386-mingw32] puma v 2.13.4

我是一个巨大的PUMA菜鸟,所以请原谅。我知道代码(python,php,只是没有rails,ruby)

所以,我试图恢复我的伙伴抛弃给我的旧项目。我已经在这里工作了12个多小时而且我已经走了很长一段路,但是我无法克服这个错误...而且我担心这个问题将会解决离开我的联盟,但我会试一试:

当我尝试启动应用程序时,出现此错误:

C:\ inetpub \ wwwroot \ Plex-Board> sh runserver.sh * SIGUSR2未实现,基于信号的重启不可用! * SIGUSR1未实现,基于信号的重启不可用! *** SIGHUP未实现,基于信号的日志重新开启不可用! Puma以单一模式开始......

版本2.13.4(ruby 2.3.3-p222),代号:仲夏节目的梦想 最小线程数:0,最大线程数:16 环境:生产 !无法加载应用程序:NameError:未初始化的常量Service :: Resolv C:/inetpub/wwwroot/Plex-Board/app/models/service.rb:14:in class:Service&#39 ;:来自C:/ inetpub / wwwroot / Plex-Board /的未初始化的常量Service :: Resolv(NameError)应用程序/模型/ service.rb:1:' 来自C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:472:在eager_load中的块(2个级别)!'来自C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:471:ineach' 来自C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:471:在eager_load的块中!'来自C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:469:ineach' 来自C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:469:in eager_load!'来自C:ineager_load!' 来自C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/application/finisher.rb:56:in each'来自C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/application/finisher.rb:56:inblock in module:Finisher' 来自C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:30:in instance_exec'来自C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:30:inrun' 来自C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:55:在run_initializers'中的块中来自C:/Ruby23/lib/ruby/2.3.0/tsort.rb:228:inblock in tsort_each' 来自C:/Ruby23/lib/ruby/2.3.0/tsort.rb:350:在each_strongly_connected_component'中的块(2个级别)中来自C:/Ruby23/lib/ruby/2.3.0/tsort.rb:431:ineach_strongly_connected_component_from' 来自C:/Ruby23/lib/ruby/2.3.0/tsort.rb:349:in each_strongly_connected_component'来自C:/Ruby23/lib/ruby/2.3.0/tsort.rb:347:ineach' 来自C:/Ruby23/lib/ruby/2.3.0/tsort.rb:347:来电'来自C:/Ruby23/lib/ruby/2.3.0/tsort.rb:347:ineach_strongly_connected_component' 来自C:/Ruby23/lib/ruby/2.3.0/tsort.rb:226:在tsort_each'来自C:/Ruby23/lib/ruby/2.3.0/tsort.rb:205:intsort_each' 来自C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:54:in run_initializers'来自C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/application.rb:352:ininitialize!' 来自C:/inetpub/wwwroot/Plex-Board/config/environment.rb:5:in'来自C:/Ruby23/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:inrequire' 来自C:/Ruby23/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in require'来自config.ru:3:inblock in' 来自C:/Ruby23/lib/ruby/gems/2.3.0/gems/puma-2.13.4/lib/puma/rack/builder.rb:184:in instance_eval'来自C:/Ruby23/lib/ruby/gems/2.3.0/gems/puma-2.13.4/lib/puma/rack/builder.rb:184:ininitialize' 来自config.ru:新的'来自config.ru:in' 来自C:/Ruby23/lib/ruby/gems/2.3.0/gems/puma-2.13.4/lib/puma/rack/builder.rb:170:在eval'来自C:/Ruby23/lib/ruby/gems/2.3.0/gems/puma-2.13.4/lib/puma/rack/builder.rb:170:innew_from_string' 来自C:/Ruby23/lib/ruby/gems/2.3.0/gems/puma-2.13.4/lib/puma/rack/builder.rb:161:在parse_file'来自C:/Ruby23/lib/ruby/gems/2.3.0/gems/puma-2.13.4/lib/puma/configuration.rb:129:inload_rackup' 来自C:/Ruby23/lib/ruby/gems/2.3.0/gems/puma-2.13.4/lib/puma/configuration.rb:96:in app'来自C:/Ruby23/lib/ruby/gems/2.3.0/gems/puma-2.13.4/lib/puma/runner.rb:113:inload_and_bind' 来自C:/Ruby23/lib/ruby/gems/2.3.0/gems/puma-2.13.4/lib/puma/single.rb:79:in run'来自C:/Ruby23/lib/ruby/gems/2.3.0/gems/puma-2.13.4/lib/puma/cli.rb:215:inrun' 来自C:/Ruby23/lib/ruby/gems/2.3.0/gems/puma-2.13.4/bin/puma:10:in'来自C:/ Ruby23 / bin / puma:22:inload' 来自C:/ Ruby23 / bin / puma:22:在`'

有问题的文件(C:/inetpub/wwwroot/Plex-Board/app/models/service.rb)中有这一行:

班级服务<的ActiveRecord :: Base的     belongs_to:service_flavor,polymorphic :: true     #forest_destroy:destroy_associated     after_initialize:init

attr_accessor :timeout
strip_attributes only: [:ip, :url, :dns_name], collapse_spaces: true

validates_associated :service_flavor
validates :name, presence: true, uniqueness: true, allow_blank: false
validates :url, presence: true, uniqueness: true, allow_blank: false
validates_inclusion_of :port, in: 1..65535
validates :ip, length: { minimum: 7, maximum: 45 },
    format: { with: Resolv::IPv4::Regex },
    uniqueness: { scope: :port }, allow_blank: true
validates :dns_name, length: { minimum: 2, maximum: 127 },
    uniqueness: { scope: :port }, allow_blank: true
validates :ip, presence: true, if: (:ip_and_dns_name_dont_exist)
validates :dns_name, presence: true, if: (:ip_and_dns_name_dont_exist)

def init
  @timeout ||= 5
  self.online_status ||= false
end

def ip_and_dns_name_dont_exist
    if (ip.blank? || ip.to_s.empty?) && (dns_name.blank? || dns_name.to_s.empty?)
        self.errors.add(:base, 'IP Address or DNS Name must exist')
        true
    else
        false
    end
end

def ping     ping_destination = connect_method     开始       Timeout.timeout(@timeout)做         s = TCPSocket.new(ping_destination,self.port)         S.CLOSE         self.update(online_status:true,last_seen:Time.now)         返回true       结束     救援Errno :: ECONNREFUSED       self.update(online_status:true,last_seen:Time.now)       返回true     救援超时::错误,Errno :: ENETUNREACH,Errno :: EHOSTUNREACH,SocketError       self.update(online_status:false)       返回false     结束   端

def connect_method     if!self.dns_name.blank?       self.dns_name     其他       self.ip     结束   结束 端

我可以猜出这段代码的作用,但我不确定如何修复它,或者即使它可以修复。

Sooo,任何想法?

1 个答案:

答案 0 :(得分:0)

尝试使用rails控制台,检查此类是否已加载

Resolv::IPv4::Regex

如果没有,则需要添加

gem 'rubysl-resolv'

在您的Gemfile中,然后捆绑安装