ruby on rails - Scoping require class loading, etc -


i have file booking.rb in model directory. contains class definition

class booking < activerecord::base   def self.setup_connection       wsdlurl = 'http://10.14.47.201:7001xxx/webservice/retrievebookingsbycclv1_01.wsdl'       factory = soap::wsdldriverfactory.new(wsdlurl)       @@driver = factory.create_rpc_driver       @@driver.return_response_as_xml = true     end end 

i attempt invoke method application.rb see code below.

module pnr2   class application < rails::application       ...       ...       booking.setup_connection     end   end   

this fails following when run app...

  c:/users/sg0209028/rubymineprojects/pnr2/config/application.rb:49:in   `<class:application>': uninitialized constant pnr2::application::booking (nameerror)    c:/users/sg0209028/rubymineprojects/pnr2/config/application.rb:18:in `<module:pnr2>'    c:/users/sg0209028/rubymineprojects/pnr2/config/application.rb:17:in `<top (required)> 

the reason reference line 49 removed comments in application.rb file avoid taking space in note. line 49 in original booking.setup_connection line.

i not understanding how name scoping working in rails 3. maybe don't understand when should invoking class method set constant in model object. feels should application initialization task, maybe request should somewhere else.

ib case wondering, have had code , invocation of appropriate web services working in straingth ruby (non rails) environment.

below code that

require 'soap/wsdldriver' require 'rexml/document' require 'soap/rpc/driver' wsdl_url = "http://10.14.47.202:7001/xxx/webservice/retrievebookingsbycclv1_01.wsdl" factory = soap::wsdldriverfactory.new(wsdl_url) driver = factory.create_rpc_driver driver.return_response_as_xml = true params = {"ccl" => "booking[bookingname[bookingnameitem[ticketnumber > \"123456789\"]]]", "xmlformat" => "defaultbooking"} response = driver.retrievebookingsbyccl(params) doc = rexml::document.new response puts "number of pnrs = " + rexml::xpath.first(doc, "//count").text doc.elements.each ("//origincity") {|element| puts "element = " + element.text} 

can please give newbie pointers? oh , yes realize invoking soap based services instead of ending database going have issues. prepared once connection work!

thanks in advance

chris

i realized trying use booking class in application.rb file. think going have issues because @ point application not configured, if can around those, use model, you'll have require file @ top of application.rb file:

require 'rails/all' require file.join(file.dirname(__file__), '../app/models/booking') 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -