# Page.visual\_effect

**URL:** <https://www.ruby-forum.com/t/page-visual-effect/167361>\
**Category:** Rails\
**Created:** [May 7, 2009, 1:36am UTC](https://www.ruby-forum.com/t/page-visual-effect/167361 "2009-05-07T01:36:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsmecham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f475e1/32.png) [@jsmecham](https://www.ruby-forum.com/u/jsmecham)\
**Post date:** [May 7, 2009, 1:36am UTC](https://www.ruby-forum.com/t/page-visual-effect/167361/1 "2009-05-07T01:36:03Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jsmecham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f475e1/32.png) [@jsmecham](https://www.ruby-forum.com/u/jsmecham)\
**Post date:** [May 7, 2009, 1:45am UTC](https://www.ruby-forum.com/t/page-visual-effect/167361/2 "2009-05-07T01:45:41Z")

</div>

On May 7, 12:36 am, Justin Mclachlan \<rails-mailing-l…@andreas-  
[s.net](http://s.net)\> wrote:

> 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?

maybe I’m being completely dumb, but can’t you do

render :update do  
page.insert\_html :bottom, ‘comment\_list’, :partial =\>  
‘comment’, :object =\> new\_comment  
page.visual\_effect dom\_id(new\_comment)  
end

or something along those lines ?

Fred

---

<div class="post-metadata">

**Author:** ![jsmecham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f475e1/32.png) [@jsmecham](https://www.ruby-forum.com/u/jsmecham)\
**Post date:** [May 7, 2009, 1:52am UTC](https://www.ruby-forum.com/t/page-visual-effect/167361/3 "2009-05-07T01:52:31Z")

</div>

Frederick C. wrote:

> render :update do  
> page.insert\_html :bottom, ‘comment\_list’, :partial =\>  
> ‘comment’, :object =\> new\_comment  
> page.visual\_effect dom\_id(new\_comment)  
> end
> 
> or something along those lines ?
> 
> Fred

I tried something similar (though I’m placing the comments at the top)  
and it worked – unless you submit more than one comment without  
manually reloading the page. Then it didn’t update / highlight  
correctly.

Here’s what I tried (I call them notes):

page.insert\_html :top, ‘query\_notes’, :partial =\> ‘queries/notes’,  
:collection =\> @note  
page.visual\_effect :highlight

---

<div class="post-metadata">

**Author:** ![jsmecham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f475e1/32.png) [@jsmecham](https://www.ruby-forum.com/u/jsmecham)\
**Post date:** [May 7, 2009, 2:57am UTC](https://www.ruby-forum.com/t/page-visual-effect/167361/4 "2009-05-07T02:57:39Z")

</div>

On 6 May 2009, at 16:52, Justin Mclachlan  
\<removed\_email\_address@domain.invalid

> wrote:

> > 
> 
> :collection =\> @note  
> page.visual\_effect :highlight

Aren’t you some missing method arguments there ? I’d check that  
you’re not stuffing invalid HTML into the dom (or duplicate ids or  
anything like that)

---

<div class="post-metadata">

**Author:** ![jsmecham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f475e1/32.png) [@jsmecham](https://www.ruby-forum.com/u/jsmecham)\
**Post date:** [May 7, 2009, 2:01am UTC](https://www.ruby-forum.com/t/page-visual-effect/167361/5 "2009-05-07T02:01:29Z")

</div>

Justin Mclachlan wrote:

> 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\_'removed\_email\_address@domain.invalid\_s  
end

and \_comment.html.erb:

 \<%= comment.body %\>

…

## tom

===============================================================================  
Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache

# [www.meinlschmidt.com](http://www.meinlschmidt.com) www.maxwellrender.cz www.lightgems.cz

---

<div class="post-metadata">

**Author:** ![jsmecham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f475e1/32.png) [@jsmecham](https://www.ruby-forum.com/u/jsmecham)\
**Post date:** [May 7, 2009, 2:59am UTC](https://www.ruby-forum.com/t/page-visual-effect/167361/6 "2009-05-07T02:59:20Z")

</div>

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\_'removed\_email\_address@domain.invalid\_s  
> end
> 
> and \_comment.html.erb:
> 
> \<%= comment.body %\>

That worked beautifully. Thanks.
