0

我的routes.rb文件中有以下嵌套资源

  resource :issuer do
    resources :certificates
  end

我的模型:

class Issuer < ActiveRecord::Base
  has_many :certificates
end

class Certificate < ActiveRecord::Base
  belongs_to :issuer
end

访问时出现以下错误: /issuer/2/certificates

No route matches {:action=>"edit", :controller=>"certificates"}

任何帮助将不胜感激..提前致谢!

编辑:我的rake routes

    issuer_certificates GET    /issuer/:issuer_id/certificates(.:format)          {:action=>"index", :controller=>"certificates"}
                        POST   /issuer/:issuer_id/certificates(.:format)          {:action=>"create", :controller=>"certificates"}
 new_issuer_certificate GET    /issuer/:issuer_id/certificates/new(.:format)      {:action=>"new", :controller=>"certificates"}
edit_issuer_certificate GET    /issuer/:issuer_id/certificates/:id/edit(.:format) {:action=>"edit", :controller=>"certificates"}
     issuer_certificate GET    /issuer/:issuer_id/certificates/:id(.:format)      {:action=>"show", :controller=>"certificates"}
                        PUT    /issuer/:issuer_id/certificates/:id(.:format)      {:action=>"update", :controller=>"certificates"}
                        DELETE /issuer/:issuer_id/certificates/:id(.:format)      {:action=>"destroy", :controller=>"certificates"}
4

3 回答 3

2

您应该在参考 :issuer 中使用资源(复数)而不是资源。所以请试试这个:

resources :issuers do
   resources :certificates
end

并将issuers/2/certificates工作。

于 2011-05-23T16:01:03.430 回答
1

在您的 routes.rb 文件中,您将 issuer 定义为单一资源

  resource :issuer do         # <-----  using resource instead of resources
    resources :certificates
  end 

使用单一资源,您获得的路线将不允许 :id 匹配,因此在您的示例中,

issuer/2/certificates

让你悲伤的是“2”。您应该摆脱它或将 :issuer 定义为您的 routes.rb 文件中的标准(非单一)资源。

于 2011-11-25T20:44:45.023 回答
0

您没有PUT/issuer/2/certificates. 相反,您将其定义为/issuer/2/certificates/123. 这就是为什么你得到那个错误。

如果您尝试编辑,请certificate确保生成正确的链接并包含certificate_id.

于 2011-05-25T06:24:07.380 回答