page.visual_effect

Justin Mclachlan wrote:

I have something similar to a blog post that users can add comments to. I'm use a partial to render the list of comments and a form that submits a new comment via AJAX to update the list. The AJAX call uses the same partial. My question is, how can I mark the last added comment so that I can use page.visual_effect to give it a yellow fade. Currently, I can highlight the entire block of comments. Everything I've tried causes problems. :after_create won't work, as far as I can tell, because it's wrapped into the create method and no changes have been committed to the database yet.

This seems like it should be a pretty simple task, highlighting the last change to a list rendered as from a collection, but I can't figure it out. Any thoughts?

simplest thing is to mark each comment with its ID... and then highlight element with name_id (eg)

@newpost = @post.comments.new ... render :update do |page|    page.insert_html :bellow, 'comments', :partial => 'comment', :object => @newpost    page.visual_effect :highlight, 'comment_'+@comment.id.to_s end

and _comment.html.erb:

<div id="comment_<%= comment.id%>">   <%= comment.body %> </div>

...

tom

Tom Z Meinlschmidt wrote:

@newpost = @post.comments.new ... render :update do |page|    page.insert_html :bellow, 'comments', :partial => 'comment', :object => @newpost    page.visual_effect :highlight, 'comment_'+@comment.id.to_s end

and _comment.html.erb:

<div id="comment_<%= comment.id%>">   <%= comment.body %> </div>

That worked beautifully. Thanks.