Here is an example
(it is from my course, purchases and wine, but I assume you can easiy adapt it to your needs)
class Wine < ActiveRecord::Base
has_many :purchases
end
class Purchase < ActiveRecord::Base
belongs_to :wine
end
in the purchase_controller, I have
...
def edit
@wines = Wine.find_all
@purchase = Purchase.find(params[:id])
end
...
def new
@purchase = Purchase.new
@wines = Wine.find_all
end
...
and in the purchase view for edit, I have
Editing purchase
<% form_tag :action => 'update', :id => @purchase do %>
<%= render :partial => 'form' %>
<%= submit_tag 'Edit' %>
<% end %>
<%= link_to 'Show', :action => 'show', :id => @purchase %> |
<%= link_to 'Back', :action => 'list' %>
Here is where I create the dropdownlist
the wine.name, sous-appelation and year form the label,
the wine.id is hidden in the option value attribute
Since this is the edit operation, there already is a wine selected,
hence the "selected" attribute in the dropdownlist
I hope this helps you on your way
cheers
Geert