Displaying 1 result from an estimated 1 matches for "next_month_str".
2006 Jun 08
2
how to add plugin to ActiveRecord
...efore
I save it. I can do this successfully now using this code:
class Account < ActiveRecord::Base
def before_save
self.exp_date = last_day_of_month(self.exp_date)
end
# Returns a Date object set to the last day of the current month
def last_day_of_month(date = Date.today)
next_month_str = date.year.to_s + ''-'' + (date.month + 1).to_s +
''-01''
Date.parse(next_month_str) - 1
end
end
However, this is Ruby on Rails, and I''m trying to break all my old
programming habits like making ugly code, and this looks ugly. Is there
a way to...