Forum: Ruby on Rails does select support arrays in a form with multiple models?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5201e306c37562746a8cdeebe24bef32?d=identicon&s=25 jose (Guest)
on 2006-05-24 19:35
i have a one-to-many model (an addressbook of contacts with many phone
numbers).  i want to represent a select element so that its name is an
array containing the phone_number id...

<select id="phone_number_1_location_or_kind"
name="phone_number[1][location_or_kind]">
<option value="Work">Work</option>
<option value="Home">Home</option>
<option value="Fax">Fax</option>
</select>

other form elements (such as text_field) allow for this, but i haven't
found a way of getting the select element to work with arrays.
C64e63b70be7dfed8b0742540b8b27e5?d=identicon&s=25 Mark Reginald James (Guest)
on 2006-06-14 15:49
(Received via mailing list)
jose wrote:
>
> other form elements (such as text_field) allow for this, but i haven't
> found a way of getting the select element to work with arrays.

The above should work.  Written as a helper call:

select :phone_number, :location_or_kind, %w(Work Home Fax), {}, :index
=> 1

--
We develop, watch us RoR, in numbers too big to ignore.
This topic is locked and can not be replied to.