简体   繁体   中英

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.

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 %>

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 %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM