Skip to content
This repository has been archived by the owner on Aug 21, 2018. It is now read-only.

Commit

Permalink
Add pagination to posts displayed on home page
Browse files Browse the repository at this point in the history
  • Loading branch information
twoesplease committed Jul 6, 2018
1 parent d298578 commit cb6e3ea
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Expand Up @@ -38,6 +38,10 @@ gem 'devise', '~> 4.3.0'
# Allow app to parse Markdown
gem 'redcarpet', '~> 3.0.0'

gem 'will_paginate', '>= 3.1.5'
gem 'bootstrap-will_paginate', '>= 1.0.0'


group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
Expand Down
7 changes: 6 additions & 1 deletion Gemfile.lock
Expand Up @@ -43,6 +43,8 @@ GEM
arel (8.0.0)
bcrypt (3.1.12)
bindex (0.5.0)
bootstrap-will_paginate (1.0.0)
will_paginate
builder (3.2.3)
byebug (10.0.2)
capybara (2.18.0)
Expand Down Expand Up @@ -183,13 +185,15 @@ GEM
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3)
will_paginate (3.1.6)
xpath (3.1.0)
nokogiri (~> 1.8)

PLATFORMS
ruby

DEPENDENCIES
bootstrap-will_paginate (>= 1.0.0)
byebug
capybara (~> 2.13)
coffee-rails (~> 4.2)
Expand All @@ -209,6 +213,7 @@ DEPENDENCIES
tzinfo-data
uglifier (>= 1.3.0)
web-console (>= 3.3.0)
will_paginate (>= 3.1.5)

BUNDLED WITH
1.16.1
1.16.2
15 changes: 14 additions & 1 deletion app/assets/stylesheets/application.scss
Expand Up @@ -36,6 +36,19 @@ a:link {
text-decoration: underline;
}

.pagination li {
list-style: none;
padding: .5em;
display: inline-block;
}

.pagination a {
text-decoration: none;
&:hover {
color: #63685e;
}
}

#topnav {
// please precompile and show properly on heroku!
background: #63685e;
Expand All @@ -54,7 +67,7 @@ a:link {
text-transform: uppercase;
color: #fff;
float: left;
padding: .5em
padding: .5em;
}
li {
padding: .5em 0;
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/posts_controller.rb
Expand Up @@ -3,7 +3,9 @@ class PostsController < ApplicationController
protect_from_forgery prepend: true
before_action :authenticate_user!, except: %i[index show]
def index
@posts = Post.all.order('created_at DESC')
# @posts = Post.all.order('created_at DESC')
@posts = Post.paginate :page => params[:page], :per_page => 10

end

def new
Expand Down
2 changes: 2 additions & 0 deletions app/views/posts/index.html.erb
Expand Up @@ -4,3 +4,5 @@
<p class='date'><%= post.created_at.strftime('%B %d, %Y') %></p>
</div>
<% end %>
<%= will_paginate @posts %>

0 comments on commit cb6e3ea

Please sign in to comment.