Oh so please bear with me... I have a model for bookings and a model for drivers. A driver has many bookings and a booking belongs to a driver.
When adding or editing a booking, I want the user to be able to type the username of the driver. Usernames are unique and easier for the end user than giving each driver a number.
Now this is how I have done it:
def create
if params[:booking][:driver].empty?
params[:booking][:driver] = nil
else
@driver = Driver.find(:first, :conditions => { :username => params[:booking][:driver] })
params[:booking][:driver] = @driver
end
This code works fine for submitting, but when the form is loaded, it shows the reference of the object (eg. #) and I need it to show the username. How can I change <%= f.text_field :driver %> in the form_for in the edit view to take the value of the drivers username?
Am I going about this the right way, or is there a dead easy, rails way to do what I need?