ruby on rails - Take date from Form Data but Time from Actual Time -
To specify a date for the user in a form, Therefore, when a post request is sent to the rail-application, the So a message has been saved at the end. Now when I try to get But I think that corresponds to the real time of the time when the message was made, so ouput should look like this: / p> How should I save the message so that it meets my concept? Thanks Actually I save a message like this: You can do something like this: Not very beautiful but you can make some useful method ... 21.04.2014 :
created_at data is also provided in the request to save a post:
Post [text]: "first message" post [created_at]: 21.04.2014
created_at for the message:
Message.find (1) .created_at & gt; & Gt; 2014-04-21 00:00:00
& gt; & Gt; 2014-04-21 19:52:07
@ user.message.new (message_params) def diagnosis_params params [: message] .permit (: created_at, : text) end
dt = date.pars ('21 .04.2014 ') # = & gt; Mon, April 21, 2014 tm = Time.zone.now # = & gt; Tuesday, 22 April 2014 00:34:07 MSK + 04: 00 created_it = DateTime.New (DT.U.E., DTMN, DT DAY, TMHOR, TMMM, TM. SC) # = & gt; Mon, 21 Apr 2014 00:34:07 +0000
Comments
Post a Comment