我正在使用ActiveResource 4.0,我需要让分页工作。我已经在服务器端设置了响应标头,但我无法在客户端读取它们。
我正在使用这篇很棒的博客文章:http://javiersaldana.com/2013/04/29/pagination-with-activeresource.html
我正在尝试从响应中读取标头: ActiveResource::Base.connection.response
但是我收到此错误: undefined method 'response' for #<ActiveResource::Connection:0x007f9a4f9692b8>
如何获取响应标头?
gem "activeresource-response" 来救援 .https://github.com/Fivell/activeresource-response
例如,假设服务器返回分页的标头X 极限,X 偏移,X 总计
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