Hi there,
I recently started learning Ruby on Rails. I decided to learn Rails by programming some kind of small statistic application where I can document the fuel consumption of my car - i.e. everytime I'm at the gas station I log price and amount of the gas refuled and the distance travelled since the last refuelling.
One of my models looks like this:
# start class Refuelling < ActiveRecord::Base belongs_to :car
def consumption liter/kilometer * 100 end
def liter_price price/liter end
def type_of_tires if tires "winter tires" else "normal tires" end end end # end
In my view I use this like this (simplyfied):
# start <% for r in @refuelling %> <%=h r.created_at.to_date %> <%=h r.kilometer %> <%=h r.liter %> <%=h r.price %> <%=h r.consumption %> <%=h r.liter_price %> <%=h r.type_of_tires %> <% end %> # end
Now I want to calculate the max, min, average of this consumption method, but I do not know how. I tried creating a method like ...
# start def max maximum(consumption) end # end
... in my model but that did not work.
Any hints on how to accomplish this? Thanks.
Max