2011-06-08 35 views
2

3渲染形式部分我有局部的命名空間和嵌套的資源一種形式,至今一直有疼痛感得到正常工作(「博客/職位/評論」)。我設法得到它的工作的「新」和「編輯」行爲(在評論控制器),但現在我想將其加載到「顯示」視圖父控制器(職位)的。不過,我已經嘗試過的任何東西都可以工Rails的在另一個控制器

這裏是形式是如何在「/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| %> 

我使用一個標準的嘗試調用此部分的「渲染」命令,但我得到的其中最有可能與我產生了在上面的代碼形式的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"} 

我一直在抨擊我的頭在牆上這一週了,因此任何幫助是極大的讚賞。謝謝!

+1

你有一個'@ blog','渲染局部形式定義之前@ comment'對象? – rubyprince 2011-06-08 06:19:51

+0

如果你的意思是在「@post」和「@comment」,他們是在控制器產生。 – 2011-06-08 14:51:30

回答

3

jQuery來救援!

$("div#form").load("<%= new_blog_post_comment_path(@post) -%> #blog_post_comment_form") 

如果有人知道一個更好的方法來做到這一點,我都耳朵!

相關問題