All these attributes are in the cars table. But one of the fields, 'price', is stored in a different table:
<%= text_field 'car', 'price', :size => 40 %>
'price' is an attribute of the financials table. How can I have the form submission update the field in this second table? I tried changing the param name to this:
...but that didn't work. I know this is weird, but the client has it this way due to legacy reasons, and I can't change the schema right now. Any and all suggestions are appreciated.
Thanks!
-Jason
PS: tables and attributes have been changed to protect the innocent.
This is essentially the approach I am using at the moment, but I am
convinced it can be done with the right text_field names if I could
only work it out!
Something like:
CarController ---
def update
if params[:car] # Make sure the form has been submitted
begin # Make sure the car exists
@car = Car.find(params[:id])
rescue
flash[:notice] = "Car not found"
redirect_to :action => "index"and return # Stop script
end
if @car.update_attributes(params[:car])
flash[:notice] = "Car details updated"
redirect_to :action => "edit_car", :id => @car.id and return # Stop
processing the script.
else
flash[:warning] = "Car not saved"
redirect_to :action => "edit_car", :id => @car.id
end
end
view:
<%= text_field 'car', 'maker', :size => 40 %>
<%= text_field 'car', 'owner', :size => 40 %>
<%= text_field 'car', 'color', :size => 40 %>
<%= text_field 'car.financial', 'price', :size => 40 %> # This is the
bit I have not worked out yet. It may not be possible.
Can anyone tell me if this is possible and what the text_field might
look like?