2014-07-12 51 views
1

will_paginate不能按預期運行。問題是當我點擊下一個按鈕或特定頁面時,瀏覽器不能在任何地方導航。Rails 4 will_paginate;不更改頁面

class PagesController < ApplicationController 
    def index 
    # Shout Stuff 
    @link = Link.all.paginate(:page => 1, :per_page => 1) 
    end 
end 

這是視圖

<% @link.each do |link| %> 
    <li><%= link_to link.title, 'shouts/' + link.id.to_s %></li> 
<% end %> 
<%= will_paginate @link %> 

最後的LinksController:

class LinksController < ApplicationController 
    def show 
    end 

    def new 
    @link = Link.new 
    end 

    def create 
    @link = Link.create(link_params) 
    end 

    private 

    def link_params 
     params.require(:link).permit(:title, :url) 
    end 
end 

will_paginate創建的頁面的正確數量,但它不會在任何地方瀏覽。我想也許turbolinks打破了它在軌道4,但任何想法,將不勝感激。

+0

可能是值得一提的Ruby 2.1.0 Rails的4.1 – CodeHard

+1

':頁面=> 1'應該是':page => params [:page]'。 – Pavan

回答

3

我想,那是因爲你總是送的第一頁視圖

@link = Link.all.paginate(:page => 1, :per_page => 1) 

應該

@link = Link.all.paginate(:page => params[:page], :per_page => 1) 
+0

你太快了:) – Pavan

+0

就是這樣,在那張紙上,我要去睡覺了。 – CodeHard