Rails 4 - will_paginate
Asked Answered
I

2

6

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.

Infantry answered 25/7, 2013 at 17:52 Comment(0)
O
11

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 %>
Ox answered 25/7, 2013 at 18:4 Comment(2)
Thanks - I did read the docs, but thought the will_paginate call went at top . Got it now.Infantry
Hey, sorry if this sounded rough, it was not my intention ;)Ox
F
3

In your case you dont acctually need to write:

<%= will_paginate @titles %>

Because it is in the context of the title_controller, will_paginate will assume their is a @titles variable available. Thus it is possible to just write:

<%= will_paginate %>
Fief answered 13/10, 2013 at 13:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.