Skip to content

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

@cdangelo

Description

@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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions