If you put this parameter in the model directly, as the code of the rail generator template does, it ActiveRecordwill take care of this for you
def create
@product = Product.new(params[:product])
@product.updated_at.yesterday
end
Also, you are stuck with something like:
DateTime.parse(params[:product][:update_at])
or
DateTime.civil_from_format(:local, year, month, day, hour, minutes, seconds)
But, in my experience, it .civil_from_formatdoes not work as you expected with daylight saving time.
source
share