2

I'm using ActiveResource 4.0, and I need to get pagination working. I've set the response headers on the server end, but I cannot read them on the client end.

I'm using this great blog post: http://javiersaldana.com/2013/04/29/pagination-with-activeresource.html

And I'm trying to read the headers from the response: ActiveResource::Base.connection.response

But I'm getting this error: undefined method 'response' for #<ActiveResource::Connection:0x007f9a4f9692b8>

How can I get the response headers?

Petercopter
  • 1,218
  • 11
  • 16

1 Answers1

0

gem "activeresource-response" to the rescue . https://github.com/Fivell/activeresource-response

Example, lets say server returns headers for pagination X-limit,X-offset,X-total

class Order < ActiveResource::Base
  self.format = :json
  self.site = 'http://0.0.0.0:3000/'
  self.element_name = "order" 
  add_response_method :http_response  # our new method for returned objects 
end



class OrdersController < ApplicationController
  def index
    orders = Order.all(:params=>params)     
    @orders = Kaminari::PaginatableArray.new(
      orders,{
              :limit => orders.http_response['X-limit'].to_i,
            :offset =>orders.http_response['X-offset'].to_i,
            :total_count => orders.http_response['X-total'].to_i
      }) 
  end
end
Fivell
  • 11,829
  • 3
  • 61
  • 99