Friday, April 20, 2007

Ruby on Rails date_select with bracket id

In Rails if you make a date_select in a rhtml file and put the empty brackets [] in the name, it goofs up the name. You must add the :index => rec.id on the end of the method params to get the name correct. Otherwise you get an error message like
Couldn't find Child with ID=birthdate(1i)
For example:

date_select('child[]', 'birthdate', {:index => child.id.to_s} )

Now in the controller things like Child.update(params['child']) will work.

You also may need to get the date_helper.rb and time_helper.rb patch from http://dev.rubyonrails.org/ticket/3811
if you are not up to date with Ruby revs.

TF

1 comment:

Tammer Saleh said...

This still seems to be a problem with nil ids. See this ticket.