7
月分頁我想分頁按月職位,我在Post模型與雷
class Post
include Mongoid::Document
include Mongoid::Timestamps
scope :by_month, lambda {|end_date| Post.order_by(:created_at => :asc).where(:created_at.gte => (end_date.to_date.beginning_of_month), :created_at.lte => (end_date.to_date))}
end
添加下列範圍在我的控制,我把
def show
@posts = Post.by_month(Time.now).page(params[:page]).per(20)
end
鑑於
<%= paginate @posts, :theme => 'month_theme' %>
<%= render @posts %>
問題:
- 分頁不按月工作,我想在一個頁面中顯示一個月的所有結果,通過params [:month] = 2或params [:month] = Feb取代params [:page]
- 我認爲「2011年8月」,而不是1,2
- 環月和今年一樣,當你轉到前面,而在「2011年1月」,它會轉到「2010年12月」