views:

15

answers:

1

Is there a way to submit an array using 'form_for'?

Here's an example of what I mean if I used regular html to pass the values:

<input type="text" name="product[cost][]">

Which should become:

params["product"]["cost"]

But is there any way to do this using form_for?

A: 

No, Rails interprets all form submissions as (escaped) strings. You should convert the string into an array manually on the backend inside a controller action or before_filter.

What is an example of the kind of value you're expecting the user to pass in?

Raphomet
thanks for getting back to me, I'm going to give the user ability to add more fields of the same fields. So I'll have to pass the data in an array for this to work. I might need to just not use form_for. But I like form_for for it's validation abilities to automatically places error divs around the affected fields.
I'm not sure exactly what you're trying to do, but it sounds like you could have the user type in a comma-delimited string like `"field1, field2, field3"`, then split it into an array in the controller and handle remaining business logic from there.
Raphomet
Looks like the form_for does not work with input arrays. I've used form tag which seems to work fine. Thanks.