views:

405

answers:

1

I'm running into a little hiccup with my AJAX creation of comments for posts. Everything works great but I am doing this in the index.html.erb view so the create.js.erb is finding the first div that says "comments" and inserting the comment there.

I know how to create a post specific div by using:

<div id="comments_<%= post.id %>

But how do I reference that div with the create.js.rjs? I am assuming it is to affect the first line:

page.insert_html :bottom, :comments, :partial => @comment

where it says :comments, but not sure of the syntax here. Something like :comments_<%= post.id %> seems intuitive but since it isn't a .erb file that doesn't see to work. Thoughts?

Here is my code:

/comments/create.js.rjs

page.insert_html :bottom, :comments, :partial => @comment
page[@comment].visual_effect :highlight 
page[:new_comment].reset
+1  A: 
page.insert_html :bottom, "comments_#{post.id}", :partial => @comment
Jakub Hampl
The comment seems to be saving but not updating. Here is my view code:<div id="comments_<% post.id %>" class="comments">
bgadoci
Try posting what the generated javascript looks like (using Firebug or something) to see what's wrong.
Jakub Hampl
I mean is `post` set to something?
Jakub Hampl
The log is saying I have an undefined local variable or method 'post'.
bgadoci
Ah, just had to ad the @ sign in front of site.
bgadoci