This is because #sum is an ActiveRecord method. What it is essentially doing is building the aggregation into your database query like so (in SQL):
SELECT SUM(name_of_column_to_sum) FROM table_name;
If you want to return the values and store them in a variable (#all),
SELECT * FROM table_name;
and THEN sum them, you are no longer working with an ActiveRecord query, but rather an ActiveRecord relation (an array-like object that is returned from the ActiveRecord query). So, at that point you would need to use vanilla Ruby to sum up. You could use #map and then #sum, but it would be faster and cleaner to just use #inject, like so:
invoices.inject(0){ |sum, invoice| sum + invoice.amount }