奇怪的路由问题 - 没有方法错误

时间:2011-06-15 10:46:14

标签: ruby-on-rails

在为嵌套资源加载表单时,我收到了no method错误。我有一个修复它,但它是不对的我确定。

我的routes.rb包含:

resources :orders do
     resources :comments, :technicals, :milestones
end

在我的techncials.html.erb表单的顶部,我有这个:

<%= semantic_form_for([@order, @technical]) do |f| %>

加载表单时,出现错误:

> NoMethodError in Technicals#new
> 
> undefined method `technicals_path' for
> #<#<Class:0x00000102118318>:0x000001020ec470>

如果我把它放在我的路线中,一切正常:

resources :technicals, :only => [ :create ]

我到底在做什么,如果有的话?!

编辑:我认为我的模型等都设置正确:

class Technical < ActiveRecord::Base
  belongs_to :order
end

- 编辑 -

company_order_comments GET    /companies/:company_id/orders/:order_id/comments(.:format)          {:action=>"index", :controller=>"comments"}
                           POST   /companies/:company_id/orders/:order_id/comments(.:format)          {:action=>"create", :controller=>"comments"}
 new_company_order_comment GET    /companies/:company_id/orders/:order_id/comments/new(.:format)      {:action=>"new", :controller=>"comments"}
edit_company_order_comment GET    /companies/:company_id/orders/:order_id/comments/:id/edit(.:format) {:action=>"edit", :controller=>"comments"}
     company_order_comment GET    /companies/:company_id/orders/:order_id/comments/:id(.:format)      {:action=>"show", :controller=>"comments"}
                           PUT    /companies/:company_id/orders/:order_id/comments/:id(.:format)      {:action=>"update", :controller=>"comments"}
                           DELETE /companies/:company_id/orders/:order_id/comments/:id(.:format)      {:action=>"destroy", :controller=>"comments"}
            company_orders GET    /companies/:company_id/orders(.:format)                             {:action=>"index", :controller=>"orders"}
                           POST   /companies/:company_id/orders(.:format)                             {:action=>"create", :controller=>"orders"}
         new_company_order GET    /companies/:company_id/orders/new(.:format)                         {:action=>"new", :controller=>"orders"}
        edit_company_order GET    /companies/:company_id/orders/:id/edit(.:format)                    {:action=>"edit", :controller=>"orders"}
             company_order GET    /companies/:company_id/orders/:id(.:format)                         {:action=>"show", :controller=>"orders"}
                           PUT    /companies/:company_id/orders/:id(.:format)                         {:action=>"update", :controller=>"orders"}
                           DELETE /companies/:company_id/orders/:id(.:format)                         {:action=>"destroy", :controller=>"orders"}
                 companies GET    /companies(.:format)                                                {:action=>"index", :controller=>"companies"}
                           POST   /companies(.:format)                                                {:action=>"create", :controller=>"companies"}
               new_company GET    /companies/new(.:format)                                            {:action=>"new", :controller=>"companies"}
              edit_company GET    /companies/:id/edit(.:format)                                       {:action=>"edit", :controller=>"companies"}
                   company GET    /companies/:id(.:format)                                            {:action=>"show", :controller=>"companies"}
                           PUT    /companies/:id(.:format)                                            {:action=>"update", :controller=>"companies"}
                           DELETE /companies/:id(.:format)                                            {:action=>"destroy", :controller=>"companies"}
            order_comments GET    /orders/:order_id/comments(.:format)                                {:action=>"index", :controller=>"comments"}
                           POST   /orders/:order_id/comments(.:format)                                {:action=>"create", :controller=>"comments"}
         new_order_comment GET    /orders/:order_id/comments/new(.:format)                            {:action=>"new", :controller=>"comments"}
        edit_order_comment GET    /orders/:order_id/comments/:id/edit(.:format)                       {:action=>"edit", :controller=>"comments"}
             order_comment GET    /orders/:order_id/comments/:id(.:format)                            {:action=>"show", :controller=>"comments"}
                           PUT    /orders/:order_id/comments/:id(.:format)                            {:action=>"update", :controller=>"comments"}
                           DELETE /orders/:order_id/comments/:id(.:format)                            {:action=>"destroy", :controller=>"comments"}
          order_technicals GET    /orders/:order_id/technicals(.:format)                              {:action=>"index", :controller=>"technicals"}
                           POST   /orders/:order_id/technicals(.:format)                              {:action=>"create", :controller=>"technicals"}
       new_order_technical GET    /orders/:order_id/technicals/new(.:format)                          {:action=>"new", :controller=>"technicals"}
      edit_order_technical GET    /orders/:order_id/technicals/:id/edit(.:format)                     {:action=>"edit", :controller=>"technicals"}
           order_technical GET    /orders/:order_id/technicals/:id(.:format)                          {:action=>"show", :controller=>"technicals"}
                           PUT    /orders/:order_id/technicals/:id(.:format)                          {:action=>"update", :controller=>"technicals"}
                           DELETE /orders/:order_id/technicals/:id(.:format)                          {:action=>"destroy", :controller=>"technicals"}
          order_milestones GET    /orders/:order_id/milestones(.:format)                              {:action=>"index", :controller=>"milestones"}
                           POST   /orders/:order_id/milestones(.:format)                              {:action=>"create", :controller=>"milestones"}
       new_order_milestone GET    /orders/:order_id/milestones/new(.:format)                          {:action=>"new", :controller=>"milestones"}
      edit_order_milestone GET    /orders/:order_id/milestones/:id/edit(.:format)                     {:action=>"edit", :controller=>"milestones"}
           order_milestone GET    /orders/:order_id/milestones/:id(.:format)                          {:action=>"show", :controller=>"milestones"}
                           PUT    /orders/:order_id/milestones/:id(.:format)                          {:action=>"update", :controller=>"milestones"}
                           DELETE /orders/:order_id/milestones/:id(.:format)                          {:action=>"destroy", :controller=>"milestones"}
                    orders GET    /orders(.:format)                                                   {:action=>"index", :controller=>"orders"}
                           POST   /orders(.:format)                                                   {:action=>"create", :controller=>"orders"}
                 new_order GET    /orders/new(.:format)                                               {:action=>"new", :controller=>"orders"}
                edit_order GET    /orders/:id/edit(.:format)                                          {:action=>"edit", :controller=>"orders"}
                     order GET    /orders/:id(.:format)                                               {:action=>"show", :controller=>"orders"}
                           PUT    /orders/:id(.:format)                                               {:action=>"update", :controller=>"orders"}
                           DELETE /orders/:id(.:format)                                               {:action=>"destroy", :controller=>"orders"}
                                  /orders(.:format)                                                   {:controller=>"orders", :action=>"index"}
                      root        /(.:format)                                                         {:controller=>"home", :action=>"index"}

1 个答案:

答案 0 :(得分:0)

NoMethodError in Technicals#new

controllers / technicals_controller.rb是否有“def new”? 如果没有,请尝试添加一个:

def new
 @technical = Technical.new
end