title: Ruby PUMA error: "Unable to load application: NameError: uninitialized constant Service::Resolv"
body: <p>Using Windows 10E
  ruby 2.3.3p222 (2016-11-21 revision 56859) [i386-mingw32]
  puma v 2.13.4</p>
  
  <p>I'm a HUGE PUMA noob, so please excuse me. I know code (python, php, just not rails, ruby)</p>
  
  <p>So, I'm trying to revive an old project my buddy dumped off to me. I've been working at this for 12+ hours and I've come a long way, but I can't get past this error...and I'm afraid the resolution is gonna be out of my league, but I'll give it a shot:</p>
  
  <p>When I try to launch the application, I get this error:</p>
  
  <p>C:\inetpub\wwwroot\Plex-Board>sh runserver.sh
  <strong>* SIGUSR2 not implemented, signal based restart unavailable!
  *</strong> SIGUSR1 not implemented, signal based restart unavailable!
  *** SIGHUP not implemented, signal based logs reopening unavailable!
  Puma starting in single mode...</p>
  
  <p>Version 2.13.4 (ruby 2.3.3-p222), codename: A Midsummer Code's Dream
  Min threads: 0, max threads: 16
  Environment: production
  ! Unable to load application: NameError: uninitialized constant Service::Resolv
  C:/inetpub/wwwroot/Plex-Board/app/models/service.rb:14:in class:Service': uninitialized constant Service::Resolv (NameError) from C:/inetpub/wwwroot/Plex-Board/app/models/service.rb:1:in'
  from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:472:in block (2 levels) in eager_load!' from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:471:ineach'
  from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:471:in block in eager_load!' from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:469:ineach'
  from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/engine.rb:469:in eager_load!' from C:ineager_load!'
  from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/application/finisher.rb:56:in each' from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/application/finisher.rb:56:inblock in module:Finisher'
  from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:30:in instance_exec' from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:30:inrun'
  from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:55:in block in run_initializers' from C:/Ruby23/lib/ruby/2.3.0/tsort.rb:228:inblock in tsort_each'
  from C:/Ruby23/lib/ruby/2.3.0/tsort.rb:350:in block (2 levels) in each_strongly_connected_component' from C:/Ruby23/lib/ruby/2.3.0/tsort.rb:431:ineach_strongly_connected_component_from'
  from C:/Ruby23/lib/ruby/2.3.0/tsort.rb:349:in block in each_strongly_connected_component' from C:/Ruby23/lib/ruby/2.3.0/tsort.rb:347:ineach'
  from C:/Ruby23/lib/ruby/2.3.0/tsort.rb:347:in call' from C:/Ruby23/lib/ruby/2.3.0/tsort.rb:347:ineach_strongly_connected_component'
  from C:/Ruby23/lib/ruby/2.3.0/tsort.rb:226:in tsort_each' from C:/Ruby23/lib/ruby/2.3.0/tsort.rb:205:intsort_each'
  from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:54:in run_initializers' from C:/Ruby23/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/application.rb:352:ininitialize!'
  from C:/inetpub/wwwroot/Plex-Board/config/environment.rb:5:in ' from C:/Ruby23/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:inrequire'
  from C:/Ruby23/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in require' from config.ru:3:inblock in '
  from C:/Ruby23/lib/ruby/gems/2.3.0/gems/puma-2.13.4/lib/puma/rack/builder.rb:184:in instance_eval' from C:/Ruby23/lib/ruby/gems/2.3.0/gems/puma-2.13.4/lib/puma/rack/builder.rb:184:ininitialize'
  from config.ru:in new' from config.ru:in'
  from C:/Ruby23/lib/ruby/gems/2.3.0/gems/puma-2.13.4/lib/puma/rack/builder.rb:170:in eval' from C:/Ruby23/lib/ruby/gems/2.3.0/gems/puma-2.13.4/lib/puma/rack/builder.rb:170:innew_from_string'
  from C:/Ruby23/lib/ruby/gems/2.3.0/gems/puma-2.13.4/lib/puma/rack/builder.rb:161:in parse_file' from C:/Ruby23/lib/ruby/gems/2.3.0/gems/puma-2.13.4/lib/puma/configuration.rb:129:inload_rackup'
  from C:/Ruby23/lib/ruby/gems/2.3.0/gems/puma-2.13.4/lib/puma/configuration.rb:96:in app' from C:/Ruby23/lib/ruby/gems/2.3.0/gems/puma-2.13.4/lib/puma/runner.rb:113:inload_and_bind'
  from C:/Ruby23/lib/ruby/gems/2.3.0/gems/puma-2.13.4/lib/puma/single.rb:79:in run' from C:/Ruby23/lib/ruby/gems/2.3.0/gems/puma-2.13.4/lib/puma/cli.rb:215:inrun'
  from C:/Ruby23/lib/ruby/gems/2.3.0/gems/puma-2.13.4/bin/puma:10:in ' from C:/Ruby23/bin/puma:22:inload'
  from C:/Ruby23/bin/puma:22:in `'</p>
  
  <p>The file in question ( C:/inetpub/wwwroot/Plex-Board/app/models/service.rb) has this line in it:</p>
  
  <hr>
  
  <p>class Service &lt; ActiveRecord::Base
      belongs_to :service_flavor, polymorphic: :true
      # before_destroy :destroy_associated
      after_initialize :init</p>
  
  <pre><code>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?) &amp;&amp; (dns_name.blank? || dns_name.to_s.empty?)
          self.errors.add(:base, 'IP Address or DNS Name must exist')
          true
      else
          false
      end
  end
  </code></pre>
  
  <p>def ping
      ping_destination = connect_method
      begin
        Timeout.timeout(@timeout) do
          s = TCPSocket.new(ping_destination, self.port)
          s.close
          self.update(online_status: true, last_seen: Time.now)
          return true
        end
      rescue Errno::ECONNREFUSED
        self.update(online_status: true, last_seen: Time.now)
        return true
      rescue Timeout::Error, Errno::ENETUNREACH, Errno::EHOSTUNREACH, SocketError
        self.update(online_status: false)
        return false
      end
    end</p>
  
  <p>def connect_method
      if !self.dns_name.blank?
        self.dns_name
      else
        self.ip
      end
    end
  end</p>
  
  <hr>
  
  <p>I can guess what this code does, but I'm not sure how to fix it or even if it's possible to fix.</p>
  
  <p>Sooo, any ideas?</p>