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

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -