CodeHard
CodeHard

Reputation: 125

Rails 4 will_paginate; Not changing pages

will_paginate does not function as intended. The problem is when I click the next button or a specific page, the browser does not navigate anywhere.

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

This is the view

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

And finally the 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 creates the proper number of pages but it will not navigate anywhere. I am thinking maybe turbolinks broke it in rails 4. But any ideas would be appreciated.

Upvotes: 1

Views: 755

Answers (1)

gotva
gotva

Reputation: 5998

I think it is because you always send the first page to the view

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

it should be

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

Upvotes: 4

Related Questions