Hi I am learning rails and have hit a bit of a wall.
I have created methods previousley that work fine on a single object.
However in my latest project I am trying to calculate the total cost
of a group of phonecalls and I am having difficulty creating a method
to calculate this. I have a phonecall model and phonecall has a cost
In my controller I am finding the @phonecalls
And in my view I want to say @phoncalls.total_cost
However I keep getting an undefined method error.
In my phonecall model i am trying to iterate through a block.
each do |phonecall|
totalcost += phonecall.cost
I have tried varios types of blocks, various connertaions of this
method and self.each.... but I dont seem to be getting anywhere.
I am not sure if this is because of the fact that my syntax is wrong
when dealing with a collection of objects as I am in this case.
I can iterate through those objects in the view ie for each phonecall
in @phonecalls etc and I am getting the correct output o I am happy
that the controller code is working fine.
Any help would be muchly appreciated as I am struggling to find help
in my books and online.