Forum: Ruby on Rails Collection_select problem

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.
Chris (Guest)
on 2006-01-28 19:30
I have my customer object with title attribute
: @customer.title

Where title is "Mr","Mrs", etc....

In edit/create from i have:
 @titles=["Mr","Mrs","Miss"]

how do i create a selection box that sets itself to the value of
@customer.title??

This doesn't work:
<%=collection_select(:customer, :title, @titles)%>

Any help would be appreciated,
THanks
Craig W. (Guest)
on 2006-01-28 20:08
(Received via mailing list)
On Sat, 2006-01-28 at 18:30 +0100, Chris wrote:
>
> This doesn't work:
> <%=collection_select(:customer, :title, @titles)%>
>
> Any help would be appreciated,
> THanks
----

Agile book suggests something like this in controller

  PAYMENT_TYPES = [
    [ "Check",          "check" ],
    [ "Credit Card",    "cc"    ],
    [ "Purchase Order", "po"    ]
  ].freeze

and something like this in rhtml

<%=
     options = [["Select a payment option", ""]] + Order::PAYMENT_TYPES
     select("order", "pay_type", options)
   %>

HTH

Craig
This topic is locked and can not be replied to.