dropdown box

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