Dropdown box

i am new to ruby on rails in my project i have two tables documents and
dependents
and in dependents there is a column called name and i want to populate
this column data in dropdown list and after selecting the name in the
dropdown list i want to store it in documents table column called
dependents_name for this what should be the controller and view.
please…

thanks

Basic idea:

View:

<%= form_tag({:action => ‘update’, :id => @document}) %>

<%=
collection_select(:document, :dependent_id, Dependent.find(:all), :id,
:name)
%>

<%= submit_tag ‘Commit’ %>

(The form triggers the ‘update’ method, storing your @document.id in
params[:id]. The value that is selected by the user in the drop-down
box will be stored in params[:document][:dependent_id])

Controller

def update
@document = Document.find(params[:id])
@document.update_attributes(params[:document])
# this line will update each attribute of @document with the
corresponding attribute in params[:document]. In this case, it’s the
same as if you did: @document.dependent_id =
params[:document][:dependent_id] and then @document.save.
end

This example stores the dependent_id rather than the dependant_name,
but that’s what you should store. Then in your Document model you
should have:

belongs_to :dependents

and in your Dependent model

has_many :documents

Then you can view the name of the dependent for any document like this:

@document.dependent.name