1
所以如果我在表格中使用date_select
並且製作模型validates_presence_of :date
。我會收到一個錯誤消息:日期不能爲空,即使我已經選擇了一個日期。Mongoid date_select and validates_presence_of
# in the form
<div class="field">
<%= f.label :date %><br />
<%= f.date_select :date %>
</div>
# in the model
validates_presence_of :date
我已閱讀,mongoid在railscast mongoid截屏與date_select
一個問題,但是,這是一箇舊的輔導,所以我不知道,如果問題仍然存在,因爲我似乎無法找到一個解決方案線上。
如果我使用text_field
,驗證根本不起作用。我可以在不提交任何日期的情況下按提交,並將重定向到錯誤頁面而不是正確的紅色警告。
只適用於舊版本的Mongoid。瞭解更多[這裏](https://github.com/netguru/mongoid-sadstory) –