Ajax replacing partial not working

I am trying to get a comment system going for a page and I want to use
ajax to replace the partial holding the comments. When I press submit my
little indicator icon pops up and nothing happens, but if I refresh the
page the comment is there.
This is the code I have for the comment in my controller:
def comment
id = params[:id]
user_id = params[:user_id]
comment = params[:comment]
arr = {:place_id => id, :user_id => user_id, :comment => comment,
:time_added => Time.now}
place_comment = PlaceComment.new(arr)
place_comment.save
bar = Bar.find_by_id(id)
render :update do |page|
page.replace_html ‘comments’, :partial => ‘_comments’, :object =>
bar
end
end

My partial called comments.rhtml looks like this:

<% if [email protected]_comments.nil? %> <% for comments in @bar.place_comments %>
<%= image_tag url_for_file_column(comments.user, "photo", "thumb") unless comments.user.photo.nil? %> <%= h comments.user.username %> said:
<%= h comments.comment %>

<% end %> <% end %>

And I have a div wrapping the partial where the id is called “comments”,
I can’t see what I am doing wrong.

You don’t need the underscore when referencing a partial this way.

Change: page.replace_html ‘comments’, :partial =>
‘_comments’, :object => bar

To this: page.replace_html ‘comments’, :partial =>
‘comments’, :object => bar

Aaron W. wrote:

You don’t need the underscore when referencing a partial this way.

Change: page.replace_html ‘comments’, :partial =>
‘_comments’, :object => bar

To this: page.replace_html ‘comments’, :partial =>
‘comments’, :object => bar

That didn’t work, and I thought you did have to use the underscore using
rjs rendering (according to what I read in AWD) correct me if I’m wrong.

I had this problem for awhile and it was because of the underscore.
You might want to specify the controller when calling that partial and
see if that works.

:partial => ‘controllerName/comments’

Ok I finally got it, the problem was that I was passing in a bar object
to the partial in the ajax updater controller method and the partial had
no clue what to do with it, so I simply had to pass it an @bar instead
of bar object and viola working fine now. Thanks for the help.