2016-06-01 2 views
0

AJAX와 Kaminari을 사용하고 있습니다. AJAX 부분은 잘 작동합니다. 그러나, 내 컨트롤러에서 말할 때 .per (3) 그것은 모든 객체 시간 3을 반환합니다. 따라서 9 개의 래서 피가 있다면 27 개의 래서 피 (중복 생성)를 반환합니다. 내가 .per (1)라고 말할 때만 유일한 개체를 얻습니다. 그러나 모든 단일 개체에 대해 새 페이지를 원하지 않습니다.Rails & Kaminari : 페이지 매김을 통해 복제본을 얻을 수 있습니다

이 문제로 도와주세요. 미리 감사드립니다.

내 컨트롤러 :

class RecipesController < ApplicationController 
    skip_before_action :authenticate_user! 
    def index 
    if params[:search] 
     @recipes = Recipe.search(params[:search]).order('created_at DESC').page(params[:page]).per(3) 
    else 
     @recipes = Recipe.order('created_at DESC').page(params[:page]).per(3) 
    end 
    end 
end 

내보기 :

<div class="container is-medium" id="product-recipe"> 
    <%= render @recipes %> 
</div> 

<% if @recipes.present? %> 
    <div class="apple_pagination" id="paginator"> 
    <%= paginate @recipes, :remote => true %> 
    </div> 
<% end %> 

index.js.erb :

$('#product-recipe').html('<%= escape_javascript render(@recipes) %>'); 
$('#paginator').html('<%= escape_javascript(paginate(@recipes, :remote => true).to_s) %>'); 

답변

-1

나는 쉽고 신속 발견 에. 앞으로도 같은 문제를 겪을 수있는 사람들에게.

내 조리법 부분에 나는 recipes.each do | recipe | .... 그게 문제 였어. 그 줄을 제거하면 중복 문제가 해결 됐어.

관련 문제