Friday 15 March 2013

ruby on rails - undefined method `stringify_keys' for Object -



ruby on rails - undefined method `stringify_keys' for Object -

i new world of ruby , rails (started week ago, background php). i've got class here acts factory.

i next error :

undefined method `stringify_keys' #

i understand constructor (.new) expects hash instead of object (why ?) but, although spent couple of hours searching www, didn't come viable solution @ point.

i want inject soap object constructor. constructor pretty straightforward, puts object parameter in instance variable supposed store it. i've been looking methods turn object proper hash saw bunch of old posts rather dirty hacks. i'd rather quit programming utilize them ^^.

i never thought doing cause headache...

thanks tips !

class="snippet-code-html lang-html prettyprint-override">class webservices::webservicefactory def initialize (type, url, login, password, protocol = "soap") @type, @protocol, @url, @login, @password = type, protocol, url, login, password case @protocol.capitalize when "soap" requestor = webservices::soap::soap.new(url, login, password) end @class = @type.constantize.new(requestor) end def getservice homecoming @class end end

the initialize method can take whatever arguments define, doesn't need hash, , in fact, code above looks have 5 arguments can of type.

are wanting pass soap object argument of initialize?

if are, (assuming using version of ruby >= 2.0)

class webservices::webservicefactory def initialize(requestor:, type:) @class = type.constantize.new(requestor) end end

if want class handle details of creating soap object, maybe work you:

module webservices class webservicefactory services = { soap: 'webservices::soap::soap' } def initialize(type:, protocol: :soap, params: {}) homecoming unless services.key?(protocol.to_sym) requestor = services[protocol.to_sym].constantize.new(params[:url], params[:login], params[:password]) @class = type.constantize.new(requestor) end end end

ruby-on-rails

No comments:

Post a Comment