Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4 - will_paginate

This is my first attempt using will_paginate (I know! Where have I been??)

titles_controller.erb

  def index
    @titles = Title.active.sorted.paginate(:page => params[:page])
  end

index.html.erb

<% will_paginate @titles.each do |title| %>

Error:

undefined method `total_pages' for #<Enumerator:0x00000002bacaf0>

WTF am I doing wrong? Thanks in advance.

like image 603
Katie M Avatar asked Jul 25 '13 17:07

Katie M


1 Answers

Please read will paginate docs. You need to write:

<%= will_paginate @posts %>

There is no need for adding each.

So entire view would look like:

<% @titles.each do |title| %>
  <!-- do smth with title -->
<% end %>

<%= will_paginate @titles %>
like image 101
Lucas Avatar answered Oct 04 '22 21:10

Lucas