how to save german date text_field in database

Herman Müller wrote:

Hi Ruby Comunity!

To display a database stored date like %Y-%m-%d into a text_field with
german format %d.%m.Y. is not so difficult. For conversion you can do
something like

<%= f.text_field :date_test, :value =>
@tbl_datum.date_test.strftime('%d.%m.%Y')%>

or use a helper.

But how can I save it from the form back INTO the database.

I tried it like in Rubycast Nr. 32 "time in textfield" but I think it's
not the same because you have to convert the date first from %d.%m.%Y to
database format%Y-%m-%d.

I tried many (3-days long), but nothings work.

Can somebody help me please, I'm really desperate:-(

Thanks ahead for every proposal!

Regs,

Herman

This is how I do it. Unless until I digg into i18n

Put into application.rb

def update_date(*args)
  rec = args.shift
  args.each do |e|
    d,m,y,time = params[rec][e].split(/\.| /)
    params[rec][e] = y + '-' + m + '-' + d + ' ' + time unless y.nil?
  end
end

Then call:
  update_date(:doc, :time_created, :time_closed)

before you update attributes in your controller.

by
TheR