Forum: Ruby on Rails will_paginate with group_by

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F04a22457fcbfee2afc77e77482abe08?d=identicon&s=25 Rails List (railslist)
on 2008-12-24 19:14
I am trying to use will_paginate with group_by but i keep getting
"undefined method `total_pages' for".

--Controller--

@records = Record.paginate( :conditions => ['this_id = ? and that_id =
?',session[:this_id],session[:that_id]], :page => params[:page],:order
=> 'created_at DESC', :per_page => 2).group_by { |c|
c.created_at.to_date }

--view--

<% @records.each do |d, records| %>
<b><%= d %></b>
  <% for r in records %>
    <p><%= link_to r.title, :action => "action", :id => r.id %></p>
  <% end %>
<% end %>
<%= will_paginate @records %>


any help is greatly appreciated.
F04a22457fcbfee2afc77e77482abe08?d=identicon&s=25 Rails List (railslist)
on 2008-12-25 07:26
Silly me!

Here is how I should have written it.

1.  Remove the group_by from controller
2.  Place it in view


--Controller--

@records = Record.paginate( :conditions => ['this_id = ? and that_id =
?',session[:this_id],session[:that_id]], :page => params[:page],:order
=> 'created_at DESC', :per_page => 2)


--view--

<% @records.group_by { |c|
c.created_at.to_date }.each do |d, records| %>
<b><%= d %></b>
  <% for r in records %>
    <p><%= link_to r.title, :action => "action", :id => r.id %></p>
  <% end %>
<% end %>
<%= will_paginate @records %>
This topic is locked and can not be replied to.