RJS replace_html MADNESS!

I’m listing comments within a div, id=“comments”. Whenever a new
comment is added, the list is supposed to update with all of the
comments for a given element.

The problem is that the div updates with the comment I’ve entered
followed by all of the comments that were already listed, except for
the first one. So if I enter a new comment I’ll get the list of
comments which were already attached to the element, followed by the
comment I’ve entered, followed by the list of comments again with the
exception of the very first comment in this list. Argh!

This is an intermittent error, but I’m not doing anything funky with
sessions or caching or anything, really and truly.

Very, very strange. It seems as if I’ve got the correct code that
should do this properly:

Relevant controller code:

 @comments = Comment.find(:all, :conditions => ["element_id = ?",

@element.id], :order => ‘created_at’ )

View:

<%= render :partial => 'comment' %>

Partial (the whole enchilada here):

Comments

<% for comment in @comments -%>
<% @comment = comment %>

<%= @comment.account.login %> says:

<% if @admin or (not @session[‘account’].nil? and comment.account_id
== @session[‘account’].id) -%>

<%= link_to_remote "delete", :url => { :controller => 'site', :action => 'delete_comment', :id => @comment.id }, :confirm => 'Are you sure you wish to delete this comment?' %>

<%= in_place_field 'Comment', @comment, 'body', nil, { :class => 'comment', :cols => 50, :rows => 5 } %> <% else -%> <%= textilize_without_paragraph comment.body %> <% end -%>

<% end -%>

RJS:

page[:comments].replace_html :partial => ‘comment’
page[:comment_form].replace_html :partial => ‘new_comment’

Any help or insights would be very, very, very much appreciated.

View:

<%= render :partial => 'comment' %>

Partial (the whole enchilada here):

Comments

<% for comment in @comments -%>
<% @comment = comment %>

<%= @comment.account.login %> says:

<% if @admin or (not @session[‘account’].nil? and comment.account_id
== @session[‘account’].id) -%>

<%= link_to_remote
“delete”, :url => { :controller => ‘site’, :action =>
‘delete_comment’, :id => @comment.id }, :confirm => ‘Are you sure you
wish to delete this comment?’ %>


<%= in_place_field ‘Comment’, @comment, ‘body’, nil, { :class =>
‘comment’, :cols => 50, :rows => 5 } %>
<% else -%>
<%= textilize_without_paragraph comment.body
%>

<% end -%>

<% end -%>

RJS:

page[:comments].replace_html :partial => ‘comment’
page[:comment_form].replace_html :partial => ‘new_comment’


where is the div id/action where creating a new comment link is? is the
rjs file the corresponding action-named file? if there’s more code out
there, it may help. (nothings certain)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs