I want to paginate posts by month so I added following scope in Post model
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
In my controller I put
def show
@posts = Post.by_month(Time.now).page(params[:page]).per(20)
end
In view
<%= paginate @posts, :theme => 'month_theme' %>
<%= render @posts %>
Problems:
- pagination is not working by month, I want to show all result of a month in a page, replacing params[:page] by params[:month]=2 or params[:month]=Feb
- How do I view 'August 2011' instead of 1,2
- Loop month and year like when you goto previous while in 'Jan 2011' it will goto 'Dec 2010'