如何检查页面是否在首页中,否则如何继续进入控制器的下一页? 我在此方法中使用kaminari gem [Kaminari Gem]进行分页
我的控制器中有这个
class PostsController < ApplicationController
def index
if @posts.first_page? # Check if if first page
# show only the first 9 posts
@posts = Post.first(9).page(params[:page]).per(9)
else
# Otherwise proceed to 2nd page or next pages and drop the first 9 pages if it is first_page
@posts = Post.drop(9).first(9).page(params[:page]).per(9)
end
end
end
但是执行该条件时我不知何故报错:
因为在我当前的设置中,它在视图中看起来像这样:
第一部分
// show first 9 posts
Post1
Post2
Post3
Post4
Post5
Post6
Post7
Post8
Post9
第二部分
// Display Static Banner
Banner Contents is displayed
第三部分
// Set the page to display ?page=2 and when click load-more button it will proceed to next pages
Post10
Post11
Post12
Post13
Post14
Post15
Post16
Post17
Post18
在第三部分下面,我有这个按钮可以执行下一页:
<a href="#">Load More </a>
反正控制器中的@posts
是否处于调节状态?