Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

ActiveResource NameError: wrong constant name with complex xml tag #33

Open
cdangelo opened this Issue · 3 comments

4 participants

@cdangelo

Hi all,
I'm using ActiveResource to communicate with a "custom" REST application.
My model use the ":from" to customize the url and it receives an xml response.
find(:one, :from => "/XXX/service/Decreto/"+id.to_s+"/caricaDocumento")
The server is a java application that serialize objects using XStream. In the xml I have some tag names with full class name (for example it.mypackage.MyClass).
When ActiveResource parse the xml to create attributes the system go in error with

NameError: wrong constant name it.mypackage.MyClass
from /home/ruby/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.6/lib/active_resource/base.rb:1428:in const_defined
?'
from /home/ruby/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.6/lib/active_resource/base.rb:1428:infind_or_creat
e_resource_for'
from /home/ruby/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.6/lib/active_resource/base.rb:1278:in block in load
'
from /home/ruby/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.6/lib/active_resource/base.rb:1264:ineach'
from /home/ruby/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.6/lib/active_resource/base.rb:1264:in load'
from /home/ruby/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.6/lib/active_resource/base.rb:1006:ininitialize'

The problem in find_or_create_resource_for is caused by const_defined? with a parameter that contains "it.mypackage.MyClass" (with dot)

It can be resolved changing the line
resourcename = name.to_s.camelize
with
resource_name = name.to_s.gsub(/\W+/, '').camelize

or better using an external method that can be overrided

@pachiara

I've the same problem!

Help me please!!!!

@felipecsl

Same here.. really annoying

here is a quick hack found on airbrake support page:

class ActiveResource::Base
  alias_method :old_find_or_create_resource_for, :find_or_create_resource_for  unless self.respond_to?(:old_find_or_create_resource_for) 

  def find_or_create_resource_for(name)
    name = name.to_s.gsub(".","_").camelcase.to_sym
    old_find_or_create_resource_for(name)
  end  
end
@RaVbaker

Is it planned to be fixed soon or we should monkeypatch to deal with it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.