I have a table column - valid_to, which should represent a date: 30 days from the time the entry was saved into database. But how can I do such a thing in model? E.g. in controller I can do such thing this way:
@baby = baby.create(baby_params.
merge( :valid_to => DateTime.current + 30 )
In view I can use hidden field in the form:
<%= f.hidden_field :valid_to => DateTime.current + 30 %>
so is there a way to do such a thing in model? I tried defining self.valid_to before_validation but for no avail: in irb my valid_to column is just nil. To add: I store it as datetime not string.
UPDATE
solution in the end was:
before_validation :set_valid_to, :on => :create
def set_valid_to
self[:valid_to] = 30.days.from_now
end
and lived this thing in module, but that's another story...