Forum: Ruby on Rails Can you apply effects to elements create in same RJS file?

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.
Nigel T. (Guest)
on 2006-05-08 14:08
I am trying to create a new element in a list and highlight it.
I am doing the following in my rjs file:

page.insert_html  :after, 'bananalist_header', :partial => 'banana'
page.visual_effect :highlight, "banana#{banana.id}", :duration => 1

The first line creates a new element with the id= 'banana3' say...
The second line then tries to highlight the new element.

This script fails as the second element doesn't exist before the script
starts running. Is there some way to make this work? If I change the
second line to reference an existing element 'banana1' say, then it
highlights it fine.

Any suggestions?

Cheers
Nigel
Jonathan V. (Guest)
on 2006-05-08 14:34
(Received via mailing list)
It works for me, I do that quite often. You're probably not
highlighting the right id, or maybe you've got the same id in your
document twice.

-Jonathan.
Alan F. (Guest)
on 2006-05-08 14:39
Nigel T. wrote:
> I am trying to create a new element in a list and highlight it.
> I am doing the following in my rjs file:
>
> page.insert_html  :after, 'bananalist_header', :partial => 'banana'
> page.visual_effect :highlight, "banana#{banana.id}", :duration => 1

Could it be that it's supposed to be #{@banana.id} ?   (I don't know,
just guessing).

Alan
Kevin O. (Guest)
on 2006-05-08 19:53
(Received via mailing list)
On Monday, May 08, 2006, at 12:08 PM, Nigel T. wrote:
>starts running. Is there some way to make this work? If I change the
>Posted via http://www.ruby-forum.com/.
>_______________________________________________
>Rails mailing list
>removed_email_address@domain.invalid
>http://lists.rubyonrails.org/mailman/listinfo/rails

All the lines in the RJS file fire simultaneously.

If you wrap the second line in a delay(0.1), it should work fine and
really not be noticable.

_Kevin
This topic is locked and can not be replied to.