我已经创建了一个带有 mongoid 的 rails 应用程序,但我在DATE遇到了一个问题
我创建了一个名为“张贴”的脚手架
当我编辑日期时,它会更新....
我在这里遵循 Railscast #238 Mongoid 的说明
有我的posting.rb 文件
class Posting
include Mongoid::Document
field :title
field :description
field :comments
field :published, :type => Date
end
这是我的 _from.html.erb
<%= form_for(@posting) do |f| %>
<% if @posting.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@posting.errors.count, "error") %> prohibited this posting from being saved:</h2>
<ul>
<% @posting.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :title %><br>
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :description %><br>
<%= f.text_field :description %>
</div>
<div class="field">
<%= f.label :published %><br>
<%= f.date_select :published %>
</div>
<div class="field">
<%= f.label :comments %><br>
<%= f.text_area :comments %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
最后是我的 show.html.erb 文件
<p id="notice"><%= notice %></p>
<p>
<strong>Title:</strong>
<%= @posting.title %>
</p>
<p>
<strong>Description:</strong>
<%= @posting.description %>
</p>
<p>
<strong>published:</strong>
<%= @posting.published %>
</p>
<p>
<strong>Comments:</strong>
<%= @posting.comments %>
</p>
<%= link_to 'Edit', edit_posting_path(@posting) %> |
<%= link_to 'Back', postings_path %>