# select ... :index =\> nil is not working

**URL:** <https://discuss.rubyonrails.org/t/select-index-nil-is-not-working/32068>\
**Category:** rubyonrails-talk\
**Created:** [July 19, 2008, 5:15am UTC](https://discuss.rubyonrails.org/t/select-index-nil-is-not-working/32068 "2008-07-19T05:15:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shuaib\_Zahda](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@Shuaib\_Zahda](https://discuss.rubyonrails.org/u/Shuaib_Zahda)\
**Post date:** [July 19, 2008, 5:15am UTC](https://discuss.rubyonrails.org/t/select-index-nil-is-not-working/32068/1 "2008-07-19T05:15:44Z")

</div>

Dear all

I have been trying to get this piece of code working [http://pastie.org/236978](http://pastie.org/236978)

\<div class="category"\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% fields\_for "daleel[categories\_attributes]", category do | category\_form| %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<p\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;category: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= category\_form.select "category\_id", @categories, :prompt =\> "category", :index =\> nil %\>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% if category.new\_record? %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= link\_to\_function "remove", "$ (this).up('.task').remove()" %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% else %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= link\_to\_function "remove", "category\_for\_destroy(this)" %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= category\_form.hidden\_field :id, :index =\> nil %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<%= category\_form.hidden\_field :should\_destroy, :index =\> nil, :class =\> 'should\_destroy' %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% end %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\</p\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% end %\> \</div\>

The problem is this

the select statement should hide the id however, it does not work for select and it works for the hidden field. I was trying hard to get it working in the past two days. I tried to put :index =\> nil in the :options and :html\_options and the same problem did not get solved

this concept was gotten from [#75 Complex Forms Part 3 - RailsCasts](http://railscasts.com/episodes/75)

Thanks in advance

any idea

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [July 19, 2008, 11:20am UTC](https://discuss.rubyonrails.org/t/select-index-nil-is-not-working/32068/2 "2008-07-19T11:20:18Z")

</div>

Did you see the note at the bottom of that episode:

"The code for this screencast isn’t the greatest, it requires the :index option for the fields and does not work well in Rails 2. Instead I recommend going with the approach I show in Advanced Rails Recipes"

Fred
