支持前后博文的跳转

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 { .next {
float: right; float: right;
i {
margin-left: 0.275rem;
}
}
.prev i {
margin-right: 0.275rem;
} }
} }

View File

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

View File

@ -13,7 +13,9 @@ class BlogsController < ApplicationController
def show def show
@post = Post.find(params[:id]) @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 end
private private

View File

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