will_paginate can it order by day

后端 未结 1 1026
醉话见心
醉话见心 2021-01-17 04:32

SCENARIO: I have a Pictures table that contains hundreds of photos. I\'m currently using \'will_paginate\' to paginate 100 photos per page. I would like to

相关标签:
1条回答
  • 2021-01-17 05:15

    You cannot use will paginate by group/scope by date. You'll need to do this yourself. It's not terribly difficult though, you could do something like this:

    # pictures_controller.rb

    def index
      @date             = Date.parse(params[:date]) rescue Date.today
      @pictures         = Picture.where(:created_at => @date.at_midnight..@date.next_day.at_midnight)
    
      @total_pictures   = Picture.count
      @current_pictures = @pictures.size
    end
    

    # pictures/index.html.haml

    - @pictures.each do |picture|
      = #....
    
    = "Showing #{@current_pictures} pictures for #{@date}."
    = "There are a total of #{@total_pictures} pictures."
    
    = link_to 'View Previous day photos', pictures_url(:date => @date.prev_day)
    - if @date.past?
      = link_to 'View Next day photos', pictures_url(:date => @date.next_day)
    
    0 讨论(0)
提交回复
热议问题