Ryan Bates' Multi-object Forms and the date_select

I think I've found a bug with Edge.

I'm trying out Ryan Bates' multi-object form technique shown in one of
his Rails-casts (railscasts.com/episodes/75). If you use a fields_for
similar to that shown (here: http://pastie.caboo.se/110480), you get a
Server Error 500:

The problem appears to be that Rails doesn't know to put the date-
select information into an Array.

That certainly looks like it. Have a look at trac and see if anyone
else has reported this, otherwise you'll need to open a new ticket
yourself. Do you feel like taking a crack at fixing it too :wink:


You bet I do! However... not today :stuck_out_tongue:

For future Googlers, until I can get a good work around what I'm doing
is using the snazzy Chronic gem. This means I can use a simple text
field and parse the _before_type_cast version into a Date (or Time)


Future Googlers, I was wrong : )

Wrong about what, using the Cronic gem?

Mike B.

Hey Mike.

I meant my theory looks to be incorrect: that the date_select params
were the source of the trouble.

By using the Chronic gem I thought I could get rid of the date_select
field and then all would be well, but that didn't work. It appears
that it's the combination of using select fields and text fields that
causes the trouble.

I'm not really sure how to solve the problem at the moment. I'm
poking around in the AbstractRequest.parse_request_parameters code,
but I can't even get simple requests to work in IRB, so it's taking me
a little longer than I'd like it to be.


Okay, Googlers. I have this figured out. I don't have a good
solution, but I have a work-around until I can write a patch.

You'll notice in Ryan Bate's method that he has you use an ":index =>
nil" option on text_fields for your fields_for. This option is _not_
recognized by the select helper. Until I can write a patch, you need
to use the select_tag helper as follows:

options_for_select(some_options, selected_option)

It's ugly, it's fragile, and it's not DRY. However, it'll keep you
moving until I can get a patch written this weekend.



I have same trouble :frowning:

Does you already write patch for this?
I'm use rails 2.0.1
Thank you!

James Herdman wrote:

Hey Alex!

I haven’t yet. I’ve got a little busy as of late. Here’s the thing: this is already supported, it just isn’t revealed.

What I’d suggest doing in the mean time (I will write the patch this weekend for you), is using a text field and leveraging the Chronic gem to convert plain-English time phrases into Date or Time objects.

James H.

Hello James!
I'm already fix issue with date items.
All works with creating, but if i update entryes i get error - Symbol as
array index.

James Herdman wrote:

Please attach changes you have made to the ticket in Rails Trac so that someone can check and fix it.

To put this to bed (for now), the problem is how people are
_expecting_ to use the "select" helper. They're expecting to use it
like this:

select("album[]", "genre", %w[rap rock country], :index => nil)

When in fact they _should_ be using it like this:

select("album[]", "genre", %w[rap rock country], {}, { :index => nil }

In summation, this feature is already supported, it's just not as
expected. I'll be submitting a patch with documentation enhancements
and a new test to show an example of this usage.

James H.

See patch here: http://dev.rubyonrails.org/ticket/10523

James H.

I had a similar issue to the one that you're having. In my case,
date_select was handling the auto-indexing of a new record
incorrectly. See my patch:


Not sure if this helps but someone referred me to this post when they
heard about the issue I had patched.