Sha256: 678171e939bdd4ef8e3784d993aee16badbb5d73f75cd29b1f5d95a59e4b9e64
Contents?: true
Size: 1.5 KB
Versions: 1
Compression:
Stored size: 1.5 KB
Contents
= Activeresource-response This gem adds possibility to access http response object from result of activeresource call (see ActiveResource::Base#find) == Why It can be used? Such functionallity can be used for easily implementing pagination in a REST API so that an ActiveResource client can navigate paginated results. == How to use? Add dependency to your Gemfile gem "activeresource-response", "~> 0.0.3" Just open your ActiveResource class and add add_response_method :your_method_name == Full example of usage with kaminari gem Rest Client 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 end Server Side class OrdersController < ApplicationController def index @orders = Order.page(params[:page]).per(params[:per_page]) response.headers["X-total"] = @orders.total_count.to_s response.headers["X-offset"] = @orders.offset_value.to_s response.headers["X-limit"] = @orders.limit_value.to_s respond_with(@orders) end end Client Side 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
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
activeresource-response-0.0.4 | README.rdoc |