【发布时间】:2013-01-25 16:22:22
【问题描述】:
我正在尝试将我的 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 的形式发布,即 03/11/2013
如何告诉 Rails 如何正确序列化该字段?
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 mongoid