FormOption Helper

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 :

<option value="p.id">p.name (p.description)</option>

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

Thanks

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

Frederick Cheung 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 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

Thanks Fred