Skip to content

Commit bf2101d

Browse files
committedJan 12, 2020
add pagination for indexes
1 parent 41f9c6e commit bf2101d

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed
 

‎app/controllers/api/v1/devices_controller.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Api::V1::DevicesController < ApplicationController
22
def index
3-
render json: devices
3+
render json: devices.paginate(page: page)
44
end
55

66
def count
@@ -21,6 +21,10 @@ def activetimes
2121

2222
private
2323

24+
def page
25+
params[:page] || 1
26+
end
27+
2428
def devices_count
2529
Device.count
2630
end

‎app/controllers/api/v1/people_controller.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Api::V1::PeopleController < ApplicationController
22
def index
3-
render json: people
3+
render json: people.paginate(page: page)
44
end
55

66
def show
@@ -17,11 +17,15 @@ def activetimes
1717

1818
private
1919

20+
def page
21+
params[:page] || 1
22+
end
23+
2024
def people
2125
Person.all
2226
end
2327

2428
def person
2529
Person.find(params[:id])
2630
end
27-
end
31+
end

‎app/controllers/api/v1/ssids_controller.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Api::V1::SsidsController < ApplicationController
22
def index
3-
render json: ssids
3+
render json: ssids.paginate(page: page)
44
end
55

66
def count
@@ -13,6 +13,10 @@ def show
1313

1414
private
1515

16+
def page
17+
params[:page] || 1
18+
end
19+
1620
def ssids_count
1721
Ssid.count
1822
end

‎app/models/device.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
require 'oui'
21
class Device < ApplicationRecord
32
scope :more_than_five_ssids, -> { ssid.count > 5 }
43

0 commit comments

Comments
 (0)
Please sign in to comment.