支持前后博文的跳转

This commit is contained in:
yafeilee 2014-03-30 16:16:30 +08:00
parent 261ce3bfec
commit 69b90ae5fd
4 changed files with 22 additions and 5 deletions

View File

@ -23,6 +23,13 @@
.next {
float: right;
i {
margin-left: 0.275rem;
}
}
.prev i {
margin-right: 0.275rem;
}
}

View File

@ -1,4 +1,8 @@
.markdown {
word-wrap: break-word;
overflow: hidden;
@media only screen and (min-width: 40.063em) {
h1, h2, h3, h4, h5, h6 {
font-size: 1.5rem;

View File

@ -13,7 +13,9 @@ class BlogsController < ApplicationController
def show
@post = Post.find(params[:id])
@comments = Comment.all.where(post_id: @post.id)
@prev = Post.where(:created_at.lt => @post.created_at).desc(:created_at).where(:id.ne => @post.id).first
@next = Post.where(:created_at.gt => @post.created_at).asc(:created_at).where(:id.ne => @post.id).first
@comments = @post.comments
end
private

View File

@ -7,7 +7,11 @@
= render partial: 'comment', locals: { comments: @comments }
.row
.small-12.large-8.columns
a.prev href="#"
span.has-tip data-tooltip="" title="hello" Prev
a.next href="#"
span.has-tip data-tooltip="" title="hello" Next
- if @prev
= link_to blog_path(@prev), class: 'prev' do
i.fi-arrow-left
| Prev
- if @next
= link_to blog_path(@next), class: 'next' do
| Next
i.fi-arrow-right