Problem with selection lists

Hi there, I'm using what I call static tables. Not sure if that is the
right term but static tables hold a fixed size of values. For example a
country table would hold all countries. In my person table I have a
link to the country table. Whenever I create a new person I have a drop
down list where the country can selected. That works fine. But when my
Person.create function is called all I have is the country's name and
not the id. So my question is how can I get the id from the selection

Here is the way my person controller class. I stripped it down to the

class PersonController < ApplicationController
  scaffold :person

  def list
    @people = Person.find( :all )

  def new
    @person =
    @name =
    @country =
    @countries = Country.find( :all ).map { |g| [] }

  def create
    @person =[:person])
    @name =[:name])
    @country =[:country])

    Person.transaction do = @name = @country!!
      redirect_to :action => 'list'

  rescue ActiveRecord::RecordInvalid => e
    render_action 'new'

Here also my new.rhtml

<title>New Person</title>

<h1>New Person</h1>

    <% form_for :person, :url => { :action => :create } do |form| %>
      <%= error_messages_for :person %>
      <%= error_messages_for :name %>
      <%= error_messages_for :country %>

      <% fields_for :name do |n| %>
         First: <%= n.text_field :first %>
         Middle: <%= n.text_field :middle %>
         Last: <%= n.text_field :last %>
      <% end %>

        <% fields_for :country do |c| %>
          Country: <%= :name, @countries ) %>
        <% end %>

      <%= submit_tag 'Create' %>
    <% end %>

<a href="/person/list">Back</a>


I hope you can follow my chain of thoughts. Please ask if you're not.

Thanks ahead,


Try using collection_select.

Get your countries like this instead of mapping just the name to a new
@countries = Country.find(:all)

Then this in your view (assuming your foreign key is country_id):
<%= c.collection_select(:country_id, @countries, "id", "name") %>