I have a method which takes ID of project and find all payments, do the math and the output is percentage of success (target amount vs collected)
def projectCollectedMoneyPerc(id)
@project= Project.find(id)
@collected = Payment.where('project_id = ? and confirmed = true', @project.id)
@col = @collected.sum(:amount)
@perc = ((@col.to_f / @project.amount) * 100).round(0)
end
now I need to find projects which have most % success. My idea was to call this method by sort_by but I have no idea how to put ID from collection to this sort
my collection is simple
@projects=Project.where('enabled = true and enddate > ?', Time.now)
thanks
has_many,@collectedwill usually never benil, etc.