2016-06-01 3 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

私はsolutiを見つけましたに。将来同じ問題に遭遇する可能性のある人々のために。

私のレシピでは、私は@ recipes.each do | recipe | .... これは問題で、その行を削除して重複した問題を修正しました。

関連する問題