Rails DateTime field has current date/time if nil in the database -


i have form datetime field. since rails 3.2.13 doesn't support type="datetime-local" input fields yet (and i'm not ready move 4.0 beta), i'm doing manually:

<input type="datetime-local" name="person[my_date_time]"<% if @person.my_date_time %> value="<%=@person.my_date_time.strftime('%ft%t')%>"<% end %>/> 

the problem @person.my_date_time current date/time if it's nil in database. , outputs seconds screws chrome's handling of datetimes. want field empty if it's nil in database. how can tell? rails' datetime_select method handles way want.

if datetime field nil in database in application must changing or overwriting value. perhaps have default somewhere? it's not possible going on without seeing more code posted now. can post code person model , other relevant code (any gems might affect things, etc.)?

strftime("%ft%r")  # output without seconds, e.g. "2013-04-18t21:43" 

http://www.ruby-doc.org/core-1.9.3/time.html#method-i-strftime


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -