2

I have a form partial for a namespaced and nested resource ("blog/posts/comments") which so far has been a pain to get working properly. I managed to get it working for the "new" and "edit" actions (in the Comments controller), but now I want to load it into the "show" view of the parent controller (Posts). Nothing I have tried will work, though.

Here is how the form is generated in "/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| %>

I tried call this partial using a standard "render" command but I get the following error which most likely has to do with the way I generate the URL for the form in the code above:

No route matches {:action=>"create", :controller=>"blog/comments"}
actionpack (3.0.7) lib/action_dispatch/routing/route_set.rb:425:in `raise_routing_error'

Here are my routes:

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"}

I have been bashing my head off the wall with this for a week now so any help is greatly appreciated. Thanks!

2
  • 1
    do you have a @blog, @comment objects defined before rendering the partial form? Commented Jun 8, 2011 at 6:19
  • If you mean at "@post" and "@comment", they are generated in the controller. Commented Jun 8, 2011 at 14:51

1 Answer 1

3

jQuery to the rescue!

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

If anyone knows a better way to do this, I'm all ears!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.