名前空間とネストされたリソース(「ブログ/投稿/コメント」)の部分的なフォームがありますが、これまで正しく機能させるのは面倒でした。(コメントコントローラーの)「新規」および「編集」アクションで機能させることができましたが、親コントローラー(投稿)の「表示」ビューにロードしたいと思います。しかし、私が試したことは何も機能しません。
「/blog/comments/shared/_comment_form.html.erb」でフォームが生成される方法は次のとおりです。
<%= form_for([:blog, @post, @comment],
:url => { :controller => :comments, :action => (@comment.persisted? ? :update : :create) },
:html => { :id => "blog_post_comment_form", :class => "standard_form wide" }) do |f| %>
標準の「render」コマンドを使用してこのパーシャルを呼び出そうとしましたが、次のエラーが発生します。これは、上記のコードでフォームのURLを生成する方法に関係している可能性があります。
No route matches {:action=>"create", :controller=>"blog/comments"}
actionpack (3.0.7) lib/action_dispatch/routing/route_set.rb:425:in `raise_routing_error'
これが私のルートです:
blog_post_comments GET /blog/posts/:post_id/comments(.:format) {:controller=>"blog/comments", :action=>"index"}
POST /blog/posts/:post_id/comments(.:format) {:controller=>"blog/comments", :action=>"create"}
new_blog_post_comment GET /blog/posts/:post_id/comments/new(.:format) {:controller=>"blog/comments", :action=>"new"}
edit_blog_post_comment GET /blog/posts/:post_id/comments/:id/edit(.:format) {:controller=>"blog/comments", :action=>"edit"}
blog_post_comment GET /blog/posts/:post_id/comments/:id(.:format) {:controller=>"blog/comments", :action=>"show"}
PUT /blog/posts/:post_id/comments/:id(.:format) {:controller=>"blog/comments", :action=>"update"}
DELETE /blog/posts/:post_id/comments/:id(.:format) {:controller=>"blog/comments", :action=>"destroy"}
私はこれで一週間頭を壁から叩きつけてきたので、どんな助けでも大歓迎です。ありがとう!