hyp*_*jas 0 time ruby-on-rails date mongodb
大家好,我有一个模型与字段DateTime像:
include Mongoid::Document
include Mongoid::MultiParameterAttributes
field :published_on, :type => DateTime
Run Code Online (Sandbox Code Playgroud)
在我的_form.html.erb中我喜欢:
<div class="field">
<%= f.label :published_on %><br %>
<%= f.date_select :published_on %>
</div>
.
.
.
.
Run Code Online (Sandbox Code Playgroud)
当我去创建新文章时,我可以看到该字段选择日期,但我想创建一个带有日期的新文章,但没有我可以手动创建或编辑日期.
它的意思是,在stackoverflow中,例如,如果我创建一个新问题,出现日期但我看不到字段选择日期时间我也无法编辑字段.
它可以添加到我的数据库mongodb日期和时间创建新文章而不会在我的视图中显示日期时间选择新建和编辑?
它可以隐藏字段date_select并将日期添加到数据库中?
jan*_*223 10
为什么不使用在save上添加created_at的默认Mongoid时间戳.假设此时间戳仅在保存记录时创建,但它是不可更改的日期和时间.只需添加include Mongoid::Timestamps到您的模型,然后在您的展示页面上,您只需访问created_at即可显示它.