I would need to implement jQuery datetimepicker
into my Ruby on Rails 5 application. There is good documentation for jqueryui Date picker
, included two railscasts by Ryan Bates.
As datetimepicker is concerned, I suppose the only concern about rails is to produce a date and time format that rails can easily understand. Once this issue is solved, I think it is easy to add the plugin to the asset pipeline.
我需要在我的Ruby on Rails 5应用程序中实现jQuery datetimepicker。 jqueryui日期选择器有很好的文档,包括Ryan Bates的两个railscast。就像datetimepicker而言,我认为对rails的唯一关注是生成rails可以轻松理解的日期和时间格式。一旦这个问题得到解决,我认为将插件添加到资产管道很容易。
Rails DateTime format is "yyyy-mm-dd hh:mm:ss"
. For instance "2017-07-28 11:24:53"
.
So I wonder: is there any way to change the default datetimepicker
format into a DateTime rails format ?
Rails DateTime格式为“yyyy-mm-dd hh:mm:ss”。例如“2017-07-28 11:24:53”。所以我想知道:有没有办法将默认的datetimepicker格式更改为DateTime rails格式?
In the datetimepicker
official webpage, the section dedicated to using another date parser/formatter uses as example the MomentJS
library. However I could not find examples useful for Rails applications.
在datetimepicker官方网页中,专用于使用其他日期解析器/格式化程序的部分使用MomentJS库作为示例。但是,我找不到对Rails应用程序有用的示例。
jQuery UI Datepicker
has a dateFormat
option which can be easily used to set the date format to the desired format: how can this be done with datetimepicker
?
jQuery UI Datepicker有一个dateFormat选项,可以很容易地将日期格式设置为所需的格式:如何使用datetimepicker完成?
1 个解决方案
#1
1
In your view :
在你看来:
= form_for @event do |f|
= f.text_field :event_start, class: "datepicker"
In your controller
在你的控制器中
def create
# before the save
@event.event_start = params[:event][:event_start].to_datetime
end
#1
1
In your view :
在你看来:
= form_for @event do |f|
= f.text_field :event_start, class: "datepicker"
In your controller
在你的控制器中
def create
# before the save
@event.event_start = params[:event][:event_start].to_datetime
end