Forum: Ruby on Rails [Rails 3.2] accepts_nested_attributes_for and time_select

Posted by unknown (Guest)
on 2013-03-14 11:36
(Received via mailing list)
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 `Examdate`s. 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`:

~~~ {.ruby}
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
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.