I've got an problem with my update action for a nested resource.
In my app, my orders have many invoices.
Creating a new invoice, I correctly end up with the following url:
/orders/11/invoices/new
And when I edit the invoice, again, it's all correct:
/orders/11/invoices/3/edit
This works fine when the save is a success, however if the validation fails, it routes back to:
/invoices/3
I have the following in my invoices controller:
def update
# @order = Order.find(params[:order_id])
# @invoice = @order.invoices.find(params[:id])
@invoice = Invoice.find(params[:id])
respond_to do |format|
if @invoice.update_attributes(params[:invoice])
format.html { redirect_to(order_invoice_path(@invoice.order, @invoice), :notice => 'Invoice was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @invoice.errors, :status => :unprocessable_entity }
end
end
end
def edit
@invoice = Invoice.find(params[:id])
3.times { @invoice.invoice_items.build }
end
I'm assuming I need to edit the @invoice.errors part but I don't know what to change it to?
Any help appreciated. Jx