From 6229daf137f37d24d0ef3f7f87516babe66221a6 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Fri, 31 Aug 2012 16:23:44 +0400 Subject: [PATCH] [refs #374] Add paginate restriction for API --- app/controllers/api/v1/base_controller.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/controllers/api/v1/base_controller.rb b/app/controllers/api/v1/base_controller.rb index 06a950d65..2fec686d9 100644 --- a/app/controllers/api/v1/base_controller.rb +++ b/app/controllers/api/v1/base_controller.rb @@ -1,3 +1,11 @@ # -*- encoding : utf-8 -*- class Api::V1::BaseController < ApplicationController + before_filter :restrict_paginate, :only => :index + + protected + + def restrict_paginate + params[:per_page] = 30 if params[:per_page].blank? or params[:per_page].to_i < 1 + params[:per_page] = 100 if params[:per_page].to_i >100 + end end