Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6629231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:13:50+00:00 2026-05-25T22:13:50+00:00

I am using will_paginate which works like a charm for breaking up my results

  • 0

I am using will_paginate which works like a charm for breaking up my results into many pages. But on any page but the first one, my ‘sum’ method returns 0.

My view has two tables in it. The first is summary information over the entire collection and the second is the paginated collection. Page 1 of my collection shows everything perfect. Page >= 2 turns the ‘sum’ to 0 yet .count still works.

My controller:

def donations_by_season
  @season_name = params[:season_name]
  @donations = Donation.by_season(@season_name).paginate :page=>params[:page], :order=>'created_at desc', :per_page => 25
  @valid_seasons = Donation.select(:season).group(:season)
end

My Partial has these values in the top table:

    <td> <%= number_to_currency @donations.sum(:amount) %></td>
    <td><%= @donations.count %></td>

And these in the lower:

<% @donations.each do |donation| %>
<tr class="<%= cycle("odd", "even", :name => "row_class") %> ">
  <td><%= number_to_currency(donation.amount) %></td>
  <td><%= donation.iho_full %></td>
  <td><%= donation.box_code %></td>
  <td><%= donation.list_name %></td>
 </tr>
<% end %>
</table>

<p><%= will_paginate @donations %></p>

On page one, number_to_currency @donations.sum(:amount) and @donations.count are accurate. After page one, the .sum turns to 0 but the .count remains the same. How do I get the .sum to work as well?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:13:51+00:00Added an answer on May 25, 2026 at 10:13 pm

    I believe will_paginate is overriding the relation method “count”.

    If you take a look at the relation returned by the paginate method, it doesn’t contain the elements that it says its counting.

    The same for sum. It must be overwritting it, because it does not reflect what the true collection is returning.

    If you refactor your code, to use:

    @all_donations = Donation.by_season(@season_name)
    @donations = @all_donations.paginate :page=>params[:page], :order=>'created_at desc', :per_page => 25
    

    And use @all_donations, to get the count and sum metrics, it should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using django-pagination to paginate my pages. It works great, but I would like
I have an AR query using 'will_paginate' that looks like this: paginate :all, :page
I'm using will_paginate for pagination, which has been working well so far, except for
I am using will_paginate for paginating my results. Most of my site is AJAXified.
Hello I am using will_paginte plugin on two objects on a same page. Like
I'm using will_paginate as standard, but it only shows the pagination controls (< 1
I'm using the will_paginate gem. The default is 30 elements per page. How do
Is there a way in Rails (using will_paginate or any other kind of pagination)
I have a list of elements, and I've been using will_paginate up until now,
I'm using the will_paginate gem for my Rails project and it's working beautifully. Unfortunately,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.