Setting an index on a collection_select

I am creating a data entry form that allows a user to fill in multiple
rows
and save them all at once. In my controller, I create an array of
“person”
objects and pass it to the page. On the page, I have a text field like
so:

<%= text_field “person”, “name”, “index” => 1 %>

Note the “index” attribute, which sets the name and id correctly. I
would
like to do the same with a collection_select, but can’t seem to get it
to
work. Does anyone know if there is an elegant way to set the “index”
attribute of a collection_select? Something like:

<%= collection_select(‘person’, ‘type’, @person_types, ‘id’, ‘name’,
‘index’
=> 1) %>

Here’s the documentation for the text_field that describes the index
property

9

Thanks,

Jeff Dean

www.jefdean.com http://www.jefdean.com/

[email protected]

917 414 7801

Jeff Dean wrote:

Note the ?index? attribute, which sets the name and id correctly. I
would like to do the same with a collection_select, but can?t seem to
get it to work. Does anyone know if there is an elegant way to set the
?index? attribute of a collection_select? Something like:

<%= collection_select(‘person’, ‘type’, @person_types, ‘id’, ‘name’,
‘index’ => 1) %>

For select and collection_select index goes with the html_options
parameter
rather than the options parameter. So you want something like:

collection_select :person, :type, @person_types, :id, :name, {}, :index
=> 1


We develop, watch us RoR, in numbers too big to ignore.

I would like to incorporate Typo into an existing app (or vice versa).
What
is the best way to do this?

Ideally, I would love to put it in vendor-plugins and run it like an
engine

  • is this possible? If so, are there any tutorials?

Jeff Dean