Forum: Ruby on Rails page.visual_effect

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B1d2c7fa90b87c67b0bd1d1aa907e720?d=identicon&s=25 Justin Mclachlan (justinmc)
on 2009-05-07 01:36
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?
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-05-07 01:45
(Received via mailing list)
On May 7, 12:36 am, Justin Mclachlan <rails-mailing-l...@andreas-
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
B1d2c7fa90b87c67b0bd1d1aa907e720?d=identicon&s=25 Justin Mclachlan (justinmc)
on 2009-05-07 01:52
Frederick Cheung 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
1e7782e67bb34c9c67ed19d5cde5f4eb?d=identicon&s=25 Tom Z Meinlschmidt (Guest)
on 2009-05-07 02:01
(Received via mailing list)
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_'+@comment.id.to_s
end

and _comment.html.erb:

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

...

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

www.meinlschmidt.com  www.maxwellrender.cz  www.lightgems.cz
===============================================================================
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-05-07 02:57
(Received via mailing list)
On 6 May 2009, at 16:52, Justin Mclachlan
<rails-mailing-list@andreas-s.net
 > 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)
B1d2c7fa90b87c67b0bd1d1aa907e720?d=identicon&s=25 Justin Mclachlan (justinmc)
on 2009-05-07 02:59
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.
This topic is locked and can not be replied to.