Rails3 time_select does not assign correctly to model time column

310 Views Asked by At

I have just upgraded from rails 2.3.14 to 3.2.2. My time_select worked fine before the upgrade. Now the model 'start_time' and 'end_time' columns are always nil after I assign the parameters.

here is the view:

        <%=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>

Here are the parameters back in the controller:

  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"}}

here is the code that assigns the attributes to the model:

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

And here is the contents of the CalendarEvent model from the log statement:

#<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 and end_time are always nil.

they are defined as 'time' columns in schema.rb.

1

There are 1 best solutions below

1
On

It could be a mass-assignment issue, and you don't have warnings turned on. Try adding the following to your model:

attr_accessible :start_time, :end_time

You can also add this to your development.rb environment to be notified of these types of errors:

# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict