Skip to content

Instantly share code, notes, and snippets.

@nsanta
Created November 7, 2012 23:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nsanta/4035407 to your computer and use it in GitHub Desktop.
Save nsanta/4035407 to your computer and use it in GitHub Desktop.
ActiveResource is dead, long live ActiveResource 4
# GET /posts.json delivers following response body:
# {
# posts: [
# {
# title: "ActiveResource now has associations",
# body: "Lorem Ipsum"
# }
# {...}
# ]
# next_page: "/posts.json?page=2"
# }
class Post < ActiveResource::Base
self.site = "http://example.com"
self.collection_parser = PostParser
end
class PostCollection < ActiveResource::Collection
attr_accessor :next_page
def initialize(parsed = {})
@elements = parsed['posts']
@next_page = parsed['next_page']
end
end
@ecleel
Copy link

ecleel commented Nov 12, 2012

I guess you mean in line #15
self.collection_parser = PostCollection

Great Post BTW

@GrooveStomp
Copy link

@ecleel Oh wow! Now this example makes much more sense. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment