2016-06-01 2 views
1

카니발 젬을 사용하여 범주를 페이지 매김하는 레일 응용 프로그램의 페이지 매김에 사용하고 있습니다. 나는 모든 프로세스를 구현했으며 페이지 매김 링크도 보여주고있다. 그러나 이것은 테이블 요소 목록에 영향을 미치지 않습니다. 컨트롤러카미나리 표기가 테이블에 영향을 미치지 않습니다.

색인 작업

def index 
      @categories = current_user.categories 
      @categories = Kaminari.paginate_array(@categories).page(params[:page]).per(5) 
    end 

인덱스보기

<h1>Categories</h1> 
    <div class="well"> 
    <%= link_to "+ New Category", new_category_path, class: "btn btn-success" %> 
    </div> 

    <%= paginate @categories %> 
    </br> 
    <%= page_entries_info @categories %> 
    <table class="table table-bordered table-striped"> 
     <thead> 
     <tr> 
      <th>Name</th> 
      <th>Actions</th> 
     </tr> 
     </thead> 
     <tbody> 
     <% if current_user.categories.count == 0 %> 
      <tr> 
      <td colspan="2"> 
       No categories found. Click the button above to add a new one. 
      </td> 
      </tr> 
     <% else %> 
      <% current_user.categories.each do |category| %> 
      <tr> 
       <td><%= link_to category.name, category %></td> 
       <td><%= link_to "Edit", edit_category_path(category), class: "btn btn-primary" %> 
        <%= link_to "Delete", category, method: :delete, 
         data: { confirm: "You sure?" }, class: 'btn btn-small btn-danger' %> 
       </td> 
      </tr> 
      <% end %> 
     <% end %> 
     </tbody> 
    </table> 

스크린이 모든 7 명 개의 엔트리를 도시하는 상기 그림에 나타낸 바와 같이enter image description here

페이지 매김 5 페이지.

왜 작동하지 않는지 설명해주세요.

답변

2

문제는 귀하의 배열 유형과 함께 생각합니다. 다음 코드를 시도하십시오.

def index 
    @categories = current_user.categories.all 
    unless @categories.kind_of?(Array) 
     @categories = @categories.page(params[:page]).per(5) 
    else 
     @categories = Kaminari.paginate_array(@categories).page(params[:page]).per(5) 
    end 
    end 

이렇게 했습니까? 그것의 더 최적화 된 오직 필요한 레코드를 가져옵니다. rails 3,Kaminari pagination for an simple Array

+0

죄송합니다, 아미르 :

@categories = current_user.categories.page(params[:page]).per(5) 

솔루션에서 채택했다. 그들 중 누구도 일하고 ​​있지 않습니다 : | –

+0

나는 똑같은 대답을하려고했다! –

관련 문제