Add pagination to alerts index
This commit is contained in:
13
app/controllers/api/v1/base_controller.rb
Normal file
13
app/controllers/api/v1/base_controller.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class Api::V1::BaseController < ApplicationController
|
||||
DEFAULT_PAGE_SIZE = 10
|
||||
|
||||
private
|
||||
|
||||
def per_page
|
||||
(params[:per_page].presence || DEFAULT_PAGE_SIZE).to_i
|
||||
end
|
||||
|
||||
def page
|
||||
(params[:page].presence || 1).to_i
|
||||
end
|
||||
end
|
||||
@@ -3,7 +3,7 @@ module Api::V1::Parks
|
||||
before_action :set_park
|
||||
|
||||
def index
|
||||
render json: @park.alerts
|
||||
render json: @park.alerts.limit(per_page).offset((page - 1) * per_page)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user