On Mon, May 18, 2015 at 2:05 PM, Peter <peternoi...@gmail.com> wrote:

> I want to call a REST API with active resource, described here:
> http://www.redmine.org/projects/redmine/wiki/Rest_api_with_ruby

> issue = Issue.find(:all)

> and getting this error:
> expected an attributes Hash, got ["issues", [{"id"=>91663, 
> "project"=>{"id"=>77006,
> "name"=>"proj1"},....

Your `find` is expecting a singular element name back: 'issue' rather
than 'issues'.

Take a look at this:
http://www.rubydoc.info/gems/activeresource/4.0.0/ActiveResource/Collection

And do something like this:

** issue.rb **
require 'active_resource'

class Issue < ActiveResource::Base
  self.site = 'http://demo.redmine.org/'
  self.collection_parser = IssueCollection
end

** issue_collection.rb **
class IssueCollection < ActiveResource::Collection
  def initialize(parsed = {})
    @elements = parsed['issues']
  end
end

HTH,
-- 
Hassan Schroeder ------------------------ hassan.schroe...@gmail.com
http://about.me/hassanschroeder
twitter: @hassan
Consulting Availability : Silicon Valley or remote

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CACmC4yAFQ5Ue05QsyemE9YmiQ3iRJ41Uw_PhqVi020Hg-C%3DASg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to