我想知道是否有人看到了问题
我正在使用gem will_paginate
我的食谱模型:
class Recipe < ActiveRecord::Base
belongs_to :user
has_many :ingredients, dependent: :destroy
has_many :reviews, dependent: :destroy
self.per_page = 10
end
我的RecipesController:
class RecipesController < ApplicationController
skip_before_action :authenticate_user!
def index
if params[:search]
@recipes = Recipe.search(params[:search]).page(params[:page]).order("created_at DESC")
else
@recipes = Recipe.all.page(params[:page]).order('created_at DESC')
end
end
def show
@review = Review.new
@recipe = Recipe.find(params[:id])
@user = User.find(@recipe.user_id)
@full_name = @recipe.user.first_name + " " + @recipe.user.last_name
end
end
应用/视图/食谱/ index.html.erb:
<%= will_paginate @recipes %>
答案 0 :(得分:2)
对于可能关心或有同样问题的人。我找到了解决方案:
我在食谱模型中将 self.per_page = 10 更改为 WillPaginate.per_page = 10 。< / p>