1
我使用Kaminari爲我的應用程序添加分頁,但是當我點擊「下一步」轉至第二頁時,我看不到下一組內容。Kaminari分頁不顯示在第二頁,第三頁
我的看法是這樣的
<div class="span1">
<% @guestbooks.each do |g| %>
<br/>
<h4><%= g.name %>, <%= g.created_at %><br/></h4>
<%= g.message %><br/>
<p>-----------------------------------------------------------------------------------------------------------------------</p>
<% end %>
</div>
我在那裏的數據顯示第一頁上的網址是http://localhost:3000/guestbooks/new
的數據不http://localhost:3000/guestbooks/new?page=2
顯示,我不能確定爲什麼。
這裏是我的控制器
class GuestbooksController < ApplicationController
def index
@guestbooks = Guestbook.all.limit(5).page(params[:page])
end
def new
@guestbook = Guestbook.new
@guestbooks = Guestbook.all.limit(5).page(params[:page])
@guestbooks = Kaminari.paginate_array(@guestbooks).page(params[:page]).per(1)
end
def create
@guestbook = Guestbook.new(guestbook_params)
# @guestbooks = Guestbook.all.limit(1).page(params[:page])
if @guestbook.save
flash.now[:notice] = "Thanks for taking the time to write us! We greatly appreciate it!"
render :new
else
flash.now[:notice] = "Your message failed to post, please try again"
render :new
end
end
private
def guestbook_params
params.require(:guestbook).permit(:name, :email, :message)
end
end
你能告訴如何你正在控制器中獲取客人書籍? –
添加了@PardeepDhingra控制器 – Jbur43