0

我刚刚从 rails 2.3.14 升级到 3.2.2。我的 time_select 在升级之前运行良好。现在,在我分配参数后,模型 'start_time' 和 'end_time' 列始终为零。

这是视图:

        <%=label_tag("Start Time")%>
    <div class="datetime-select">
        <%=time_select(:calendar_event,:start_time,{:minute_step => 5},{:class=>'time'})%>
    </div>
    <%=label_tag("End Time")%>
    <div class="datetime-select">
        <%=time_select(:calendar_event,:end_time,{:minute_step => 5},{:class=>'time'})%>
    </div>

以下是控制器中的参数:

  Parameters: {"authenticity_token"=>"aGF3mZbZvIDiv6ikH0M8Up2HoTqyXiAFqk+6Wsjbq6g=", "calendar_event"=>{"start_date"=>"Fri Aug 31 10:30:00 +1200 2012", "calendar_resource_id"=>"", "start_time(1i)"=>"2012", "organisation_id"=>"", "start_time(2i)"=>"8", "start_time(3i)"=>"31", "booking_type"=>"WORKER", "start_time(4i)"=>"10", "end_time(1i)"=>"2012", "id"=>"", "start_time(5i)"=>"30", "end_time(2i)"=>"8", "user_id"=>"31", "end_time(3i)"=>"31", "end_time(4i)"=>"11", "description"=>"ssss", "end_time(5i)"=>"00", "end_date"=>"Fri Aug 31 11:00:00 +1200 2012"}}

这是将属性分配给模型的代码:

      @calendar_event=CalendarEvent.new(params[:calendar_event])
      logger.info(@calendar_event.inspect)

以下是日志语句中 CalendarEvent 模型的内容:

#<CalendarEvent id: nil, description: "ssss", booking_type: "WORKER", start: nil, end: nil, start_date: "2012-08-31", end_date: "2012-08-31", start_time: nil, end_time: nil, allDay: false, calendar_resource_id: nil, organisation_id: nil, user_id: 31, group_session_id: nil, created_at: nil, updated_at: nil>

start_time 和 end_time 始终为零。

它们在 schema.rb 中被定义为“时间”列。

4

1 回答 1

0

这可能是批量分配问题,并且您没有打开警告。尝试将以下内容添加到您的模型中:

attr_accessible :start_time, :end_time

您还可以将其添加到您的 development.rb 环境中,以便收到这些类型的错误的通知:

# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
于 2012-08-31T11:40:12.860 回答