Skip to content

Commit 318a341

Browse files
committed
Added will_paginate gem and pagination to /read and /news
1 parent a9d5b0e commit 318a341

6 files changed

Lines changed: 28 additions & 4 deletions

File tree

‎Gemfile.lock‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ GEM
123123
slop (3.4.4)
124124
sqlite3 (1.3.7)
125125
thor (0.18.1)
126-
tilt (1.4.0)
126+
tilt (1.4.1)
127127
tzinfo (0.3.37)
128128
unicorn (4.6.2)
129129
kgio (~> 2.6)

‎app.rb‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
require "sinatra/flash"
44
require "sinatra/contrib/all"
55
require "json"
6+
require "will_paginate"
7+
require "will_paginate/active_record"
68

79
require_relative "app/helpers/authentication_helpers"
810
require_relative "app/repositories/user_repository"

‎app/controllers/stories_controller.rb‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
class Stringer < Sinatra::Base
55
get "/news" do
6-
@unread_stories = StoryRepository.unread
6+
@unread_stories = StoryRepository.unread.page(params[:page]).per_page(15)
77

88
erb :index
99
end
1010

1111
get "/read" do
12-
@read_stories = StoryRepository.read
13-
12+
@read_stories = StoryRepository.read.page(params[:page]).per_page(15)
13+
1414
erb :read
1515
end
1616

‎app/public/css/styles.css‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,4 +496,8 @@ ul.shortcut-legend li {
496496
li.blank {
497497
list-style-type: none;
498498
height: 20px;
499+
}
500+
501+
#pagination {
502+
text-align: center;
499503
}

‎app/views/index.erb‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@
1616
<% end %>
1717
</ul>
1818
</div>
19+
<div id="pagination">
20+
<% if @unread_stories.previous_page %>
21+
<a href="?page=<%= @unread_stories.previous_page %>"><i class="icon-double-angle-left"></i> Previous</a>
22+
<% end %>
23+
Page <%= @unread_stories.current_page %> of <%= @unread_stories.total_pages %>
24+
<% if @unread_stories.next_page %>
25+
<a href="?page=<%= @unread_stories.next_page %>">Next <i class="icon-double-angle-right"></i></a>
26+
<% end %>
27+
</div>
1928
<% else %>
2029
<%= render_partial :zen %>
2130
<% end %>

‎app/views/read.erb‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@
1010
<% end %>
1111
</ul>
1212
</div>
13+
<div id="pagination">
14+
<% if @read_stories.previous_page %>
15+
<a href="?page=<%= @read_stories.previous_page %>"><i class="icon-double-angle-left"></i> Previous</a>
16+
<% end %>
17+
Page <%= @read_stories.current_page %> of <%= @read_stories.total_pages %>
18+
<% if @read_stories.next_page %>
19+
<a href="?page=<%= @read_stories.next_page %>">Next <i class="icon-double-angle-right"></i></a>
20+
<% end %>
21+
</div>
1322
<% else %>
1423
<div id="add-some-feeds">
1524
<p>Sorry, you haven't read any stories yet!</p>

0 commit comments

Comments
 (0)