Defect #4745
closed
Bug in index.xml.builder (issues)
Added by Yohann Monnier almost 15 years ago.
Updated over 14 years ago.
Description
in this file at :
xml.issues :type => 'array' , :count => @issue_count do
The ":count" parameter will cause an error calling issues from activeresource :
can't typecast "1"
["/var/lib/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:182:in `typecast_xml_value'", "/var/lib/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:208:in `typecast_xml_value'", "/var/lib/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:199:in `inject'",
If you delete this parameter, all is working fine.
My configuration
Ruby version 1.8.7 (i486-linux)
RubyGems version 1.3.5
Rack version 1.0
Rails version 2.3.5
Active Record version 2.3.5
Active Resource version 2.3.5
Action Mailer version 2.3.5
Active Support version 2.3.5
Application root /var/www/redmine
Environment development
Database adapter postgresql
Database schema version 20091227112908
REST API bug?
I tried to run the script http://www.redmine.org/wiki/redmine/Rest_api_with_ruby. Displays an error message: /home/artem/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:182:in `typecast_xml_value': can't typecast "2" (RuntimeError)
I deleted :count => @issue_count in app/views/issues/index.xml.builder and all earned.
I wrote a script rest.rb:
require 'rubygems'
require 'active_resource'
class Issue < ActiveResource::Base
self.site = 'http://www.redmine.org/'
end
issues = Issue.find(:all)
puts issues.first.subject
$ ruby rest.rb
/home/artem/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:182:in `typecast_xml_value': can't typecast "1794" (RuntimeError)
I wrote a script rest2.rb:
require 'rubygems'
require 'active_resource'
class Project < ActiveResource::Base
self.site = 'http://www.redmine.org/'
end
projects = Project.find(:all)
puts projects.first.name
$ ruby rest2.rb
Redmine
It works!
thats what i said, if you delete the :count parameter, all is working fine !
- Category set to REST API
- Status changed from New to Closed
- Assignee set to Eric Davis
- Target version set to 1.0.0 (RC)
- % Done changed from 0 to 100
- Resolution set to Fixed
I've removed the count attribute in issues.xml. It's not ideal because of the pagination won't show all of the issues but it breaks ActiveResource.
Here's the full error for the search:
RuntimeError: can't typecast "368"
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:182:in `typecast_xml_value'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:208:in `typecast_xml_value'
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `inject'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:207:in `each'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:207:in `inject'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:207:in `typecast_xml_value'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:164:in `from_xml'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.5/lib/active_resource/formats/xml_format.rb:19:in `decode'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.5/lib/active_resource/connection.rb:138:in `get'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.5/lib/active_resource/base.rb:639:in `find_every'
from /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.5/lib/active_resource/base.rb:582:in `find'
from (irb):5
from :0
Also available in: Atom
PDF