支持翻页功能
This commit is contained in:
parent
90a983fc49
commit
b5bc17a2d0
1
Gemfile
1
Gemfile
|
@ -7,6 +7,7 @@ gem 'rails', '3.2.6'
|
|||
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
||||
|
||||
gem "mongoid"
|
||||
gem "mongoid-pagination"
|
||||
gem "bson_ext"
|
||||
|
||||
|
||||
|
|
|
@ -80,6 +80,9 @@ GEM
|
|||
activemodel (~> 3.1)
|
||||
mongo (<= 1.6.2)
|
||||
tzinfo (~> 0.3.22)
|
||||
mongoid-pagination (0.2.0)
|
||||
activesupport
|
||||
mongoid
|
||||
multi_json (1.3.6)
|
||||
net-scp (1.0.4)
|
||||
net-ssh (>= 1.99.1)
|
||||
|
@ -167,6 +170,7 @@ DEPENDENCIES
|
|||
jquery-rails
|
||||
mini_magick
|
||||
mongoid
|
||||
mongoid-pagination
|
||||
nokogiri
|
||||
rails (= 3.2.6)
|
||||
redcarpet
|
||||
|
|
|
@ -14,3 +14,4 @@
|
|||
//= require jquery_ujs
|
||||
//= require 'jquery.html5-fileupload'
|
||||
//= require_tree .
|
||||
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
||||
|
||||
$(document).ready ->
|
||||
$('.pagination').click ->
|
||||
l = window.location.pathname
|
||||
page = $(this).attr('data-page')
|
||||
window.location= l + "?page=#{page}"
|
||||
false
|
||||
|
|
|
@ -8,14 +8,14 @@
|
|||
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
||||
* compiled file, but it's generally better to create a new file per style scope.
|
||||
*
|
||||
*= require_self
|
||||
*= require_tree .
|
||||
*/
|
||||
|
||||
/* http://meyerweb.com/eric/tools/css/reset/
|
||||
v2.0 | 20110126
|
||||
License: none (public domain)
|
||||
*/
|
||||
//= require_self
|
||||
//= require_tree .
|
||||
|
||||
html, body, div, span, applet, object, iframe,
|
||||
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
|
||||
|
|
|
@ -53,3 +53,13 @@ div#disqus_thread {
|
|||
border-top: 1px solid #CCC;
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
div.has_new, div.has_old {
|
||||
padding-right: 1em;
|
||||
a {
|
||||
text-decoration: none;
|
||||
}
|
||||
}
|
||||
div.has_new {
|
||||
float: right;
|
||||
}
|
||||
|
|
|
@ -2,11 +2,17 @@
|
|||
class BlogsController < ApplicationController
|
||||
def index
|
||||
type = params[:type]
|
||||
page = params[:page].to_i
|
||||
page = 1 if params[:page].nil?
|
||||
max = 3
|
||||
if type or type == ""
|
||||
@posts = Post.where(type: map[type]).order(:created_at => :desc )
|
||||
@posts = Post.paginate( :page=>page, :limit=> max ).where(type: map[type]).order(:created_at => :desc )
|
||||
else
|
||||
@posts = Post.all.order(:created_at => :desc )
|
||||
@posts = Post.paginate( :page=>page, :limit=> max ).all.order(:created_at => :desc )
|
||||
end
|
||||
@page = page
|
||||
@has_old = @posts.to_a.size == max
|
||||
@has_new = ! ( page == 1 )
|
||||
end
|
||||
|
||||
def rss
|
||||
|
|
|
@ -5,6 +5,7 @@ class Post
|
|||
CREATOR = "创业"
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
include Mongoid::Pagination
|
||||
field :title, :type => String
|
||||
field :content, :type => String
|
||||
field :type, :type=> String
|
||||
|
|
|
@ -1,4 +1,16 @@
|
|||
<div class="blogs">
|
||||
<% if @posts.size == 0 %>
|
||||
<div class="nocontent">没有新的内容, 感谢你的光临.</div>
|
||||
<% else %>
|
||||
<%= render :partial=> "post", :collection=> @posts %>
|
||||
<% end %>
|
||||
<% if @has_old %>
|
||||
<div class="has_old"><a href class="pagination" data-page="<%= @page + 1 %>">← 更早博客</a></div>
|
||||
<% end %>
|
||||
|
||||
<% if @has_new %>
|
||||
<div class="has_new"><a href class="pagination" data-page="<%= @page - 1 %>">更新博客 →</a></div>
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in New Issue