Forum: Ruby on Rails Newby: Getting "unitialized constant SockServ" -- help

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
90d386f9d88787fbda3ecb86228cbc08?d=identicon&s=25 David T-l (davidtl)
on 2006-02-16 01:23
I can't seem to find my error.  I think it's fairly basic.  Do I have to
initialize SockServ somewhere or is this error message really indicating
something else?

uninitialized constant SockServ

C:/rails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:200:in
`const_missing'
#{RAILS_ROOT}/app/controllers/mindreadr_controller.rb:15:in
`get_reordered_images'

This error occured while loading the following files:
   sock_serv.rb

This is in my ApplicationController (partila)
    def get_reordered_images
      # eventually send in image IDs, for now, send in nothing, just get
images
      @response = SockServ.open_send_receive
      # now unwrap XML response, and create list of image IDs to display
      render(:layout => false)
end


This is in my apps/models directory (sockserv.rb)
class SockServ

    def initialize
    end

    def self.open_send_receive
       # open a socket here and send the data in the xml var
       # read from the socket the response and use it as the return
    require "socket"
    STDOUT.flush

    # s is an instance of a socket
    @socket = TCPSocket.open("nnn.nnn.nnn.n", 9000)

# sending xml to just opened socket (send is std call)
    @xml = "<?xml version="1.0" ?>
             <transaction>
    	     <version> 2.0 </version>
    	     <ctrl>
       	  	   <mode> pbir </mode>
       	  	   <option>
          			<resultImageSize> 16 </resultImageSize>
       	   	   </option>
    	     </ctrl>
            </transaction>"

    @socket.send(@xml)
    @socket.recv
    end
end
5085ba37ba624a788e04a842cd09bd6e?d=identicon&s=25 Jens-Christian Fischer (Guest)
on 2006-02-16 21:37
(Received via mailing list)
>
> This is in my apps/models directory (sockserv.rb)
> class SockServ
>

try to move this class to lib/sockserv.rb

then in your controller:

     require 'sockserv'

hth
jc
This topic is locked and can not be replied to.