Rails 4 - will_paginate

This is my first attempt to use will_paginate (do I know where I was?)

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.

+6
source share
2 answers

Please read the docs section. You need to write:

 <%= will_paginate @posts %> 

No need to add each .

Thus, the whole view will look like this:

 <% @titles.each do |title| %> <!-- do smth with title --> <% end %> <%= will_paginate @titles %> 
+11
source

In your case, you do not need to write:

 <%= will_paginate @titles %> 

Since it is in the context of title_controller, will_paginate will assume that it is an available @titles variable. So you can simply write:

 <%= will_paginate %> 
+3
source

Source: https://habr.com/ru/post/950293/


All Articles