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:
class Refuelling < ActiveRecord::Base
liter/kilometer * 100
In my view I use this like this (simplyfied):
<% 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 %>
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 …
… in my model but that did not work.
Any hints on how to accomplish this?