ruby on rails - Take date from Form Data but Time from Actual Time -
To specify a date for the user in a form, 21.04.2014 :
Therefore, when a post request is sent to the rail-application, the
created_at data is also provided in the request to save a post:
Post [text]: "first message" post [created_at]: 21.04.2014 So a message has been saved at the end. Now when I try to get created_at for the message:
Message.find (1) .created_at & gt; & Gt; 2014-04-21 00:00:00 But I think that corresponds to the real time of the time when the message was made, so ouput should look like this: / p>
& gt; & Gt; 2014-04-21 19:52:07 How should I save the message so that it meets my concept? Thanks
Actually I save a message like this:
@ user.message.new (message_params) def diagnosis_params params [: message] .permit (: created_at, : text) end
You can do something like this:
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 Not very beautiful but you can make some useful method ...
Comments
Post a Comment