错误说没有路线,但似乎有

时间:2013-01-14 11:18:52

标签: ruby-on-rails routing nested

我有以下表格声明:

<%= semantic_form_for @contrat_line, 
    :url => url_for(:controller =>"/backend/orders/#{@contrat.id}/contrat_lines", 
        :action =>"create") do |f| %>

我想点击以下路线:

POST    /backend/orders/:order_id/contrat_lines(.:format)   backend/contrat_lines#create

但是当我想要显示表单时(甚至在使用它之前)我有以下错误:

No route matches {:controller=>"backend/orders/23/contrat_lines", :action=>"create"}

我会说这条路线存在,为什么说它不存在?

2 个答案:

答案 0 :(得分:1)

routes.rb代码

match "/backend/orders/:order_id/contrat_lines" => "orders#contrat_lines", :as => "contrat_lines"

然后,查看代码

<%= semantic_form_for @contrat_line, 
    :url => contrat_lines_url(:order_id => @contrat.id), 
        :action =>"create") do |f| %>

答案 1 :(得分:0)

感谢salil,我设计了以下表格:

 backend_order_contrat_lines_url(:order_id =&gt; @ contrat.id),:action =&gt;&#34; create&#34;做| f | %GT;

它适用于路线:

namespace :backend do
    resources :orders do
      resources :contrat_lines
    end
end

很多!如果你想我可以编辑你的答案并将其设置为已接受。