Maybe I'm missing something, but why add it to the database at all if it can be determined programatically from an existing column? Just create a virtual attribute:
class Subscription < ActiveRecord::Base
.
.
.
def per_month_price
self.price / 12
end
def per_month_price=(arg)
self.price = arg*12
end
end
This will function the same as if you had a per_month_price
column in your DB. It'll be more efficient as you won't have to hit the database so much, and it eliminates the (very likely) possibility that the price
and per_month_price
columns will become inconsistent with eachother somewhere, e.g. if you update one but forget to update the other.
Sorry that I didn't directly answer your question (especially to anyone coming here through Google), but this seems like a much better design to me.