Again, though, since you're dealing with ActiveRecord objects, you
probably want to make your life easier by using collection_select.
I'll try it with collection_select now, it's supposed to be at the form
partial, right? But shouldn't the collection_select logic be placed in
the controller?
THIS IS MY CURRENT CONTROLLER
class AppointmentsController < ApplicationController
before_filter :load_clients, :only => [ :new, :edit ]
# GET /appointments
# GET /appointments.xml
def index
@appointments = Appointment.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @appointments }
end
end
# GET /appointments/1
# GET /appointments/1.xml
def show
@appointment = Appointment.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @appointment }
end
end
# GET /appointments/new
# GET /appointments/new.xml
def new
@appointment = Appointment.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @appointment }
end
end
# GET /appointments/1/edit
def edit
@appointment = Appointment.find(params[:id])
end
# POST /appointments
# POST /appointments.xml
def create
@appointment = Appointment.new(params[:appointment])
respond_to do |format|
if @appointment.save
format.html { redirect_to(@appointment, :notice => 'Appointment
was successfully created.') }
format.xml { render :xml => @appointment, :status => :created,
:location => @appointment }
else
format.html { render :action => "new" }
format.xml { render :xml => @appointment.errors, :status =>
:unprocessable_entity }
end
end
end
# PUT /appointments/1
# PUT /appointments/1.xml
def update
@appointment = Appointment.find(params[:id])
respond_to do |format|
if @appointment.update_attributes(params[:appointment])
format.html { redirect_to(@appointment, :notice => 'Appointment
was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @appointment.errors, :status =>
:unprocessable_entity }
end
end
end
# DELETE /appointments/1
# DELETE /appointments/1.xml
def destroy
@appointment = Appointment.find(params[:id])
@appointment.destroy
respond_to do |format|
format.html { redirect_to(appointments_url) }
format.xml { head :ok }
end
end
private
def load_clients
# @clients = collection_select :client, :client_id
@clients = Client.find(:all)
end
end