我正在尝试将我的 rails 模型的日期字段呈现为日期选择器。
模型看起来像:
class Appointment
include Mongoid::Document
field :date, type: Date
end
_form.html.haml 视图如下所示:
= form_for @appointment, :url => {:action => :create} do |f|
= f.text_field(:date, {:class => 'datepicker'})
%button{:type => 'submit'} Book appointment
:javascript
jQuery(document).ready(function($) {
$('.datepicker').datepicker();
});
控制器动作如下所示:
class AppointmentsController < ApplicationController
def create
@appointment = Appointment.new(params[:appointment])
# rest left out for demo purposes
end
end
当“new”获取时,调用发生错误:
ArgumentError in AppointmentsController#create
argument out of range
我知道该值发布为 MM/DD/YYYY,即 2013 年 3 月 11 日
如何告诉 Rails 如何正确序列化该字段?