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
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'
const_defined ?' from /home/ruby/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.6/lib/active_resource/base.rb:1428: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:in
load' from /home/ruby/.rvm/gems/ruby-1.9.3-p194/gems/activeresource-3.2.6/lib/active_resource/base.rb:1006:in
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
resource_name = name.to_s.camelize
resource_name = name.to_s.gsub(/\W+/, '_').camelize
or better using an external method that can be overrided
Active Resource has been moved out from Rails to its own repo. Please feel free to open an issue there (you can link to this one), and if it gets fixed in their master and they decide to backport it, it'll be merged back to branch 3-2 in Rails.
I'm closing the issue here, thanks!