ruby on rails - Move method from the view in the model -
in view want display total balance. way.
controller:
def index @invoices = invoice.balance end
views:
.pull-right strong total balance: = @invoices.map(&:balance).sum
i understand it's wrong.
how can move method in model?
def total_balance invoice.all.map(&:balance).sum end
if so, how use in view?
you should write class method:
def self.total_balance sum(:balance) end
and call in view on invoices collection:
= @invoices.total_balance
Comments
Post a Comment