我有一个Charge
模型,它是Quotes
模型的一个子集。
resources :quotes do
resources :charges
end
我想在报价的编辑页面上删除charge
。
报价/ _form.html.haml
- @quote.charges.each do |charge|
%tr
%td
= link_to 'x', charge, :confirm => 'Are you sure you want to delete this charge?', :method => :delete
当我加载页面时,我得到#<#:0x0000012f8a2ea8>的未定义方法`charge_path'。我也试过了:
= link_to 'x', quote_charge_path(charge), :confirm => 'Are you sure you want to delete this charge?', :method => :delete
这似乎有效,但似乎引号ID和费用ID的顺序错误。例如,生成的网址为<a href="/quotes/11/charges/13" ...
它应该是/quotes/13/charges/11
。谁知道如何正确地做到这一点?感谢。
有趣的是,最终工作的是= link_to '×', [@quote, charge], :confirm => 'Are you sure you want to delete this charge?', :method => :delete, :class => "close"
。当我指定路径quote_charge_path([@quote, charge])
时,它正在创建错误的URL。不知道为什么......
答案 0 :(得分:2)
对于嵌套路由助手,您需要传入父对象和子对象。尝试
quote_charge_path([@quote, charge])