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
attribute.

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.

def total_cost

totalcost=0

each do |phonecall|
totalcost += phonecall.cost
end

totalcost
end

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.

Thank you

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to