# Rails: Select and html forms

**URL:** <https://www.ruby-forum.com/t/rails-select-and-html-forms/50362>\
**Category:** Rails\
**Created:** [December 15, 2005, 6:20pm UTC](https://www.ruby-forum.com/t/rails-select-and-html-forms/50362 "2005-12-15T18:20:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jersingh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b487fb/32.png) [@jersingh](https://www.ruby-forum.com/u/jersingh)\
**Post date:** [December 15, 2005, 6:20pm UTC](https://www.ruby-forum.com/t/rails-select-and-html-forms/50362/1 "2005-12-15T18:20:56Z")

</div>

I’m close to getting this to work, but not quite there. I’m trying to  
implement a dropdown control, with the current choice selected.  
I have the following code in the view:

```
  5 <select id="product_product_type" name="product[product_type]">
  6 <%=
  7 types = ProductType.find(:all, :order => "product_type")
  8 options_from_collection_for_select( types, :id, :product_type, 

```

selected=@product\_type\_id)  
9 %\>  
10 \</select

Which renders the following:

Product type

... Supplies

However, in the browser the “Supplies” item isn’t displaed on load, but  
the blank first option is. Anyone see what I’m doing wrong?

---

<div class="post-metadata">

**Author:** ![jersingh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b487fb/32.png) [@jersingh](https://www.ruby-forum.com/u/jersingh)\
**Post date:** [December 15, 2005, 8:28pm UTC](https://www.ruby-forum.com/t/rails-select-and-html-forms/50362/2 "2005-12-15T20:28:49Z")

</div>

Joe,

I found this thread on another list, I’m working on it now…I’ll let  
you know  
if I come up with a working solution.

[http://wrath.rubyonrails.org/pipermail/rails/2005-January/001905.html](http://wrath.rubyonrails.org/pipermail/rails/2005-January/001905.html)

---

<div class="post-metadata">

**Author:** ![jersingh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b487fb/32.png) [@jersingh](https://www.ruby-forum.com/u/jersingh)\
**Post date:** [December 15, 2005, 8:36pm UTC](https://www.ruby-forum.com/t/rails-select-and-html-forms/50362/3 "2005-12-15T20:36:30Z")

</div>

jschairb wrote:

> Joe,
> 
> I found this thread on another list, I’m working on it now…I’ll let  
> you know  
> if I come up with a working solution.
> 
> [http://wrath.rubyonrails.org/pipermail/rails/2005-January/001905.html](http://wrath.rubyonrails.org/pipermail/rails/2005-January/001905.html)

This works, it’s probably not the best implementation…but it works.

[http://wiki.rubyonrails.com/rails/pages/HowtoUseFormOptionHelpers](http://wiki.rubyonrails.com/rails/pages/HowtoUseFormOptionHelpers)

look for the section called ‘A collection\_select like helper’ I copied  
that code into application\_helper.rb and then used his view  
implementation. Worked for me, although I had to change the last part  
in the view from :

@page.section\_id

to just

page.section\_id

Hopefully this will get you going. Later.

---

<div class="post-metadata">

**Author:** ![jersingh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b487fb/32.png) [@jersingh](https://www.ruby-forum.com/u/jersingh)\
**Post date:** [December 15, 2005, 10:20pm UTC](https://www.ruby-forum.com/t/rails-select-and-html-forms/50362/4 "2005-12-15T22:20:52Z")

</div>

Try this:

\<%= collection\_select(:product, :product\_type, types, :id,  
:product\_type, { :include\_blank =\> true }) %\>

It works fine for me.

SandroDS

On 12/15/05, Joe E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> 10 </select
> 
> ```
> 
> However, in the browser the “Supplies” item isn’t displaed on load, but  
> the blank first option is. Anyone see what I’m doing wrong?
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Sandro Duarte  
Analista de Sistemas  
TRE-RS/SI
