2014-11-21 23 views
0

我已經實現了will_paginate,現在我想將默認頁面更改爲ruby變量的日期。我會怎麼做呢?Paginate上的自定義鏈接

要多一點精確:我的目標是有1個每頁日期和都屬於此日期此頁面

從視圖中摘錄的數據:

def show 
    @waves = @location.infos.paginate(page: params[:page], per_page: 7) 
    gon.watch.infos = @location.infos 
    respond_with(@location) 

從片段控制器:

<table class= "table table-striped"> 
      <thead> 
       <th><strong>Day</strong></th> 
       <th><strong>Swell Size</strong></th> 
       <th><strong>Swell Rating</strong></th> 
       <th><strong>Wind Speed</strong></th> 
       <th><strong>Temperature</strong></th> 
      </thead> 
      <tbody> 
       <!-- <%= will_paginate @waves, previous_label: "Previous day", next_label: "Next day", renderer: BootstrapPagination::Rails %> -->    
       <%= will_paginate(@waves, :renderer => PaginationListLinkRenderer) %> 
       <% @waves.each do |wave| %> 
       <tr> 
        <td><%= Time.at(wave.day.to_i).to_s.chomp("-0800")%></td> 
        <td><%= wave.size_min%>-<%= wave.size_max%><small>ft</small></td> 
        <td><% swell = wave.swell_rating %> 
<td><%= wave.wind_speed%><small>mph</small></td> 
        <td><%= wave.temperature%><small>°F</small> </td> 

回答

0

在這種情況下,您並不真正分頁infos。您正在爲這些記錄分配created_on屬性。

所以:

  • 確保您有對這些記錄
  • 搶通過created_on分組這些記錄created_on。原始的sql或範圍將完成一項工作。 (範圍我們不會返回適當的對象)
  • 當你有一個created_on日期的數組時,你需要創建某種分頁控件來顯示它們。我想你可能可以使用will_paginate作爲數組。
  • 裝入相關信息範圍的選定日期:@location.infos.for_date(params[:date])

基本上,你想要做什麼,需要費些力氣。

+0

感謝您的回覆。所以,我在記錄上創建了一個名爲day的屬性,這個屬性是我想要使用的unix時間戳。然而,我在哪裏創建sql查詢(鍵入什麼文件等)和分頁控制。你能提供一些示例代碼嗎? – 2014-11-21 20:28:31