我将尝试在更新发票后使我的路由正常工作。
我有一个包含多个发票的订单,并在我的routes.rb文件中设置如下:
resources :orders do
resources :invoices
end
resources :invoices
在我的发票控制器中:
def update
@invoice = Invoice.find(params[:id])
respond_to do |format|
if @invoice.update_attributes(params[:invoice])
format.html { redirect_to(invoice_path(@invoice), :notice => 'Invoice was successfully updated.') }
else
format.html { render :action => "edit" }
end
end
end
我可以通过以下方式创建发票:
/orders/1/invoices/new
但是当我保存或更新时,我被发送到:
/invoices/1
我需要重定向回订单发票路径:
/orders/1/invoices/1
我也尝试将重定向更改为:
redirect_to(order_invoice_path(@order, @invoice), :notice => 'Invoice was successfully updated.')
这个方法可以工作,但是它会把我发送到错误的URL,其中订单ID与发票ID相同...
任何帮助将不胜感激。
-- 更新 --
如果我在我的发票控制器中尝试以下操作,我也会遇到错误...
redirect_to(order_invoice_path(@order, @invoice)
No route matches {:action=>"show", :controller=>"invoices", :order_id=>nil, :id=>#<Invoice id: 6, order_id: 17, invoice_id: nil, created_at: "2011-06-26 17:49:01", updated_at: "2011-06-26 17:49:01">}