Last active
August 29, 2015 13:58
-
-
Save squidbits/9980574 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get '/blog' do | |
@css = ["base.css","blog.css"] | |
@posts = Posts.all.reverse | |
@posts_per_page = 5 | |
@pages = (@posts.count / @posts_per_page).ceil + 1 | |
@page = params[:page].to_i | |
if @page <= 0; then @page = 1; end | |
if @page > @pages; then @page = @pages; end | |
@first_post = ( ( @page - 1 ) * @posts_per_page ) | |
@last_post = ( ( @page * @posts_per_page ) - 1 ) | |
@page_prev = @page - 1 | |
@page_next = @page + 1 | |
@display_posts = @posts[@first_post..@last_post] | |
erb :blog | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="pure-u-1-1 l-box"> | |
<% @display_posts.each do |r, a| %> | |
<div class="blog-post"> | |
<div class="blog-title"> | |
<h1><%= r.title %><h1> | |
</div> | |
<div class="blog-body"> | |
<%= r.body %> | |
</div> | |
<div class="blog-time"> | |
<h6><%= r.timestamp %></h6> | |
</div> | |
</div> | |
<br> | |
<% end %> | |
<div class="blog-nav"> | |
<center> | |
<% if @page > 1 %> | |
<a href="<%= link_to "/blog?page=" + @page_prev.to_s %>">Previous Page</a> | |
<% end %> | |
<% 15.times do %> | |
| |
<% end %> | |
<% if @page < @pages %> | |
<a href="/blog?page=<%= @page + 1%>">Next Page</a> | |
<% end %> | |
</center> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment