json - Can Rails automatically parse datetime received from form text_field -
can rails automatically parse datetime received form's text_field?
# in view <div class="field"> <%= f.label :created_at %><br /> <%= f.textfield :created_at %> </div> # in controller params[:product][:updated_at].yesterday
currently i'm following error:
undefined method `yesterday' "2010-04-28 03:37:00 utc":string
if putting param model directly, rails generator boilerplate code does, activerecord
takes care of you
def create @product = product.new(params[:product]) @product.updated_at.yesterday #will succeed #rest of method end
other stuck like:
datetime.parse(params[:product][:update_at])
or
datetime.civil_from_format(:local, year, month, day, hour, minutes, seconds)
but, in experience .civil_from_format
doesn't work you'd expect daylight savings time.
Comments
Post a Comment