Setting a default value in collection_select

Could anybody cast some light on these:

  1. How can I set a default value in a collection_select? To be specific,
    have a class ‘Platform’, and I want to set the platform_code (a field of
    Platform) to be ‘ORA’ (which exists in the Platform table).
    I tried many variations of the following code in my view, but in vain:
    <% @selected = ‘ORA’ %>
    <%= collection_select “sac_table_platform”, “platform_code”,
    Platform.find(:all, :order => “platform_code”),
    :platform_code, :platform_code, { :selected => @selected } %>

  2. How can I build my own list of collection_select, e.g., a list of
    people, say, to show [Adam, Bob, Charley] on the collection_select for
    corresponding values [‘A’, ‘B’, ‘C’] in a table (which already exists),
    use it in my view?


View this message in context:
Sent from the RubyOnRails Users mailing list archive at

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs