I've got a method that caclulates an amount of roylaties owed to an author.
It works like this:
calculate_royalty(object_id)
Right now, I'm using it in a view and looping through each individual author's products and spitting out a number. Like this:
<%= @author.products.each do |product| %>
<%= @author.calculate_royalty(product.id) %>
<% end %>
Right now, that gives me a single number. What I've been trying to do is load all of those numbers into an array in my model so I can total them. I trid this:
def total_author_royalties
products do |p|
calculate_royalty(p.id)
end
end
But the array just returns as a hash of the product objects for that author. I figured once I have the values in the array, I can use Array.inject to add them all up.