# Setting an index on a collection\_select

**URL:** <https://www.ruby-forum.com/t/setting-an-index-on-a-collection-select/64121>\
**Category:** Rails\
**Created:** [June 22, 2006, 8:02am UTC](https://www.ruby-forum.com/t/setting-an-index-on-a-collection-select/64121 "2006-06-22T08:02:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![s450r1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/87869e/32.png) [@s450r1](https://www.ruby-forum.com/u/s450r1)\
**Post date:** [June 22, 2006, 8:02am UTC](https://www.ruby-forum.com/t/setting-an-index-on-a-collection-select/64121/1 "2006-06-22T08:02:16Z")

</div>

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

> **[ActionView::Helpers::FormHelper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#M00038)**
>
> Form helpers are designed to make working with resources much easier compared to using vanilla HTML.

9

Thanks,

Jeff Dean

[www.jefdean.com](http://www.jefdean.com) [http://www.jefdean.com/](http://www.jefdean.com/)

removed\_email\_address@domain.invalid

917 414 7801

---

<div class="post-metadata">

**Author:** ![s450r1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/87869e/32.png) [@s450r1](https://www.ruby-forum.com/u/s450r1)\
**Post date:** [June 22, 2006, 8:27am UTC](https://www.ruby-forum.com/t/setting-an-index-on-a-collection-select/64121/2 "2006-06-22T08:27:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![s450r1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/87869e/32.png) [@s450r1](https://www.ruby-forum.com/u/s450r1)\
**Post date:** [July 30, 2006, 3:45am UTC](https://www.ruby-forum.com/t/setting-an-index-on-a-collection-select/64121/3 "2006-07-30T03:45:25Z")

</div>

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
