[Rails 3.2] accepts_nested_attributes_for and time_select

Hi, I am upgrading a Rails application from Rails 3.1.11 to 3.2.12, but
have a problem with accepts_nested_attributes_for in conjunction with
multipart attributes.

The app is used to manage oral exams, so there is a model Exam, which
has
many Examdates. When creating an exam, I can also create the
examdates,
consisting of a date, a start time and an end time. While the date field
is
edited using a text field (with a jQuery date picker), the start and end
times are selected using a time_select form helper.

The examdates are then created using accepts_nested_attributes_for:

class Exam < ActiveRecord::Base

  has_many :examdates, :dependent => :destroy
  accepts_nested_attributes_for :examdates, :allow_destroy => true
  ...
end

class Examdate < ActiveRecord::Base

  belongs_to :exam
  validates_presence_of :date, :from, :to # date + time fields
  ...
end

When I create a new exam, the following request is issued:

Started POST "/exams" for 127.0.0.1 at 2013-03-14 10:11:32 +0100
Processing by ExamsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"...",
"exam"=>{"title"=>"test", "number"=>"123", "examstype"=>"Oral exam",
"deadline
"=>"29.03.2013", "examdates_attributes"=>{"0"=>{"date"=>"29.03.2013",
"from(3i)"=>"", "from(2i)"=>"", "from(1i)"=>"", "from(4i)"=>"00",
"from(5i)"=>"00", "to(3i)"=>"", "to(2i)"=>"", "to(
1i)"=>"", "to(4i)"=>"00", "to(5i)"=>"00", "dur"=>"12",
"_destroy"=>"false"}}}, "button"=>""}

The exam is then created in the controller using @exam = Exam.new(params[:exam]).

When I run this code using Rails 3.1.11, everything works fine. But if I
upgrade to Rails 3.2.12, the validation fails because the :from and :to
fields got no values. If I change the start time/end time form fields
into
text fields, the validation succeeds again.

So for me it seems that the accepts_nested_attributes_for has some
problems with attributes split into multiple parts (like for date_select
or
time_select).

Does anyone know how to solve this problem?

Best Regards,
Björn

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs