0

My rails date picker field sends date time info broken into different values in params hash like :

Parameters: {"commit"=>"Save",
 "interview_date(3i)"=>"29",
 "interview_date(1i)"=>"2013",
 "interview_date(4i)"=>"20",
 "interview_date(5i)"=>"13",
 "interview_date(2i)"=>"8}

How can I make it send the date time as one proper string?

  Parameters: {"commit"=>"Save",
     "interview_date"=>"2013-8-29 20:8:13"}

I know Rails will convert this into date, but that happens only when my model has interview_date as attribute. ActiveRecord recognizes and converts it into interview_date. In my case I am storing this information in a model named Response in an attribute named 'answer'. So rails does not convert it as it does not match the name of attribute.

user1570144
  • 479
  • 3
  • 17
  • If this is for an ActiveRecord object then you don't need to worry about this, Rails will do it for you behind the scenes. Is there some sort of error you are receiving? – Artin Boghosian Aug 29 '13 at 21:08

1 Answers1

0

You could change the data being sent before the ajax call like so

(...).on("ajax:beforeSend", function(event, xhr, settings) {
    settings.data += "&interview_date="+formatted_date_string;
});

and format that date string using each of those values from above.

Update: But it seems like Rails can convert that information for you - Where is the Rails method that converts data from `datetime_select` into a DateTime object?

Community
  • 1
  • 1
Cole Pilegard
  • 582
  • 2
  • 11