# FormOption Helper

**URL:** <https://www.ruby-forum.com/t/formoption-helper/145134>\
**Category:** Rails\
**Created:** [August 6, 2008, 10:51am UTC](https://www.ruby-forum.com/t/formoption-helper/145134 "2008-08-06T10:51:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vanight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/a698b9/32.png) [@vanight](https://www.ruby-forum.com/u/vanight)\
**Post date:** [August 6, 2008, 10:51am UTC](https://www.ruby-forum.com/t/formoption-helper/145134/1 "2008-08-06T10:51:45Z")

</div>

Hi,

I’m trying to generate a select with this :

select(“music”, “music\_location\_id”, MusicLocation.find(:all, :order =\>  
“name ASC”).collect {|p| [p.name, p.id] }, { :include\_blank =\> true })

I need to add a description because the name is very “cryptic” and I’d  
like to do something like :

p.name (p.description)

I don’t know how I can do it with HTML option field. The api is not  
telling much about it.

Thanks

---

<div class="post-metadata">

**Author:** ![vanight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/a698b9/32.png) [@vanight](https://www.ruby-forum.com/u/vanight)\
**Post date:** [August 6, 2008, 10:55am UTC](https://www.ruby-forum.com/t/formoption-helper/145134/2 "2008-08-06T10:55:06Z")

</div>

On Aug 6, 9:51 am, David N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi,
> 
> I’m trying to generate a select with this :
> 
> select(“music”, “music\_location\_id”, MusicLocation.find(:all, :order =\>  
> “name ASC”).collect {|p| [p.name, p.id] }, { :include\_blank =\> true })

Rails just sticks the first part of each of those arrays in the option  
description. If p.name isn’t what you want, then just put something  
else there.

Fred

---

<div class="post-metadata">

**Author:** ![vanight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/a698b9/32.png) [@vanight](https://www.ruby-forum.com/u/vanight)\
**Post date:** [August 6, 2008, 11:02am UTC](https://www.ruby-forum.com/t/formoption-helper/145134/3 "2008-08-06T11:02:18Z")

</div>

Frederick C. wrote:

> On Aug 6, 9:51ï¿½am, David N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > Hi,
> > 
> > I’m trying to generate a select with this :
> > 
> > select(“music”, “music\_location\_id”, MusicLocation.find(:all, :order =\>  
> > “name ASC”).collect {|p| [p.name, p.id] }, { :include\_blank =\> true })
> 
> Rails just sticks the first part of each of those arrays in the option  
> description. If p.name isn’t what you want, then just put something  
> else there.
> 
> Fred

The thing is that sometime, description is empty so I can’t just put  
p.description  
but I would like p.name (p.description)

I guess there’s something I can put in the HTML option hash but it’s not  
described in the API apart for :include\_blank

Maybe there’s something like :option\_key =\> “#{p.name}  
(#{p.description})”,  
do someone knows about it?

David

---

<div class="post-metadata">

**Author:** ![vanight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/a698b9/32.png) [@vanight](https://www.ruby-forum.com/u/vanight)\
**Post date:** [August 6, 2008, 11:09am UTC](https://www.ruby-forum.com/t/formoption-helper/145134/4 "2008-08-06T11:09:10Z")

</div>

On Aug 6, 10:02 am, David N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > Rails just sticks the first part of each of those arrays in the option  
> > description. If p.name isn’t what you want, then just put something  
> > else there.
> 
> > Fred
> 
> The thing is that sometime, description is empty so I can’t just put  
> p.description  
> but I would like p.name (p.description)

I don’t think you understood me - you can put any bit of ruby you want  
there, as long as it evaluates to a string (or something that looks  
like it).  
For example “#{p.name} - #{p.description}”

Fred

---

<div class="post-metadata">

**Author:** ![vanight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/a698b9/32.png) [@vanight](https://www.ruby-forum.com/u/vanight)\
**Post date:** [August 6, 2008, 11:30am UTC](https://www.ruby-forum.com/t/formoption-helper/145134/5 "2008-08-06T11:30:24Z")

</div>

Thanks Fred
