开发者

No Route Matches error - with Nested Resource

I have the following Nested Resource in my routes.rb file

  resource :issuer do
    resources :certificates
  end

My Models:

class Issuer < ActiveRecord::Base
  has_many :certificates
end

class Certificate < ActiveRecor开发者_运维问答d::Base
  belongs_to :issuer
end

I get the following error when i visit: /issuer/2/certificates

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

Any help would be appreciated.. Thanks in advance!

EDIT : MY 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"}


You should use resources (plural) instead of resource in refer to :issuer. So please try this:

resources :issuers do
   resources :certificates
end

and issuers/2/certificates will work.


In your routes.rb file you are defining issuer as a singular resource

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

With singular resources, the routes you get won't allow an :id to be matched, so in your example,

issuer/2/certificates

it's the "2" that's giving you grief. You should either get rid of it or define :issuer as a standard (non-singular) resource in your routes.rb file.


You don't have PUT defined for /issuer/2/certificates. instead you have it defined for /issuer/2/certificates/123. That's why you get that error.

If you are trying to edit the certificate then make sure you generate a correct link and include certificate_id.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜