# Rjs

**URL:** <https://www.ruby-forum.com/t/rjs/102384>\
**Category:** Rails\
**Created:** [February 8, 2006, 1:43pm UTC](https://www.ruby-forum.com/t/rjs/102384 "2006-02-08T13:43:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sucrenoir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@sucrenoir](https://www.ruby-forum.com/u/sucrenoir)\
**Post date:** [February 8, 2006, 1:43pm UTC](https://www.ruby-forum.com/t/rjs/102384/1 "2006-02-08T13:43:54Z")

</div>

I am playing with the new .rjs stuff in edge rails.  
I am doing stuff like :  
page.replace\_html ‘scoops\_tot’, @scoops.size

1. I want to add my own javascript functions to the page object.  
Is it possible and how ?

2. I am trying to update several fields, but i would like a to have a  
dekay between the updates :  
@anoclicks.each{|aclick|  
page.replace\_html ‘click\_number\_’+aclick.scoop.id.to\_s ,  
aclick.scoop.clicks\_tot.to\_i + aclick.scoop.anoclicks\_tot.to\_i  
page.visual\_effect :Pulsate, “click\_me\_#{aclick.scoop.id}”  
}

---

<div class="post-metadata">

**Author:** ![sucrenoir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@sucrenoir](https://www.ruby-forum.com/u/sucrenoir)\
**Post date:** [February 8, 2006, 2:26pm UTC](https://www.ruby-forum.com/t/rjs/102384/2 "2006-02-08T14:26:40Z")

</div>

Hi,

On 8 Feb 2006, at 12:43, jm goom wrote:

I haven’t used rjs yet, but I have got the “Rails Recipes” beta book  
(well worth buying BTW).

> 1. I want to add my own javascript functions to the page object.  
> Is it possible and how ?

Reading through the file\*, I see this method which may be what you want:

# Writes raw JavaScript to the page.

def \<\<(javascript)  
@lines \<\< javascript  
end

> 1. I am trying to update several fields, but i would like a to have a  
> dekay between the updates :

You want something like this (from the book):

page.delay(3) do  
page.alert @rails\_version  
end

which I’m sure you can adapt for your purposes.

Jon

- actionpack/lib/action\_view/helpers/prototype\_helper.rb

---

<div class="post-metadata">

**Author:** ![sucrenoir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@sucrenoir](https://www.ruby-forum.com/u/sucrenoir)\
**Post date:** [February 8, 2006, 3:50pm UTC](https://www.ruby-forum.com/t/rjs/102384/3 "2006-02-08T15:50:16Z")

</div>

jm goom wrote:

> Thank you for your answer  
> I have the book in front of me (the pdf of course)  
> I did not see this \<\< method, but just found it in the last version of  
> the doc ! Great !
> 
> For the delay, i cannot get it working more than once.  
> I want to execute an effect for each item in an array and each time  
> apply the same delay… I am going to play with that \<\< thing.
> 
> Thanks a lot 🙂

I haven’t tried it, but it may be possible to nest delay blocks.

page.delay(3) do  
page.do\_something  
page.delay(3) do  
page.do\_something\_again  
end  
end

\_Kevin

---

<div class="post-metadata">

**Author:** ![sucrenoir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@sucrenoir](https://www.ruby-forum.com/u/sucrenoir)\
**Post date:** [February 8, 2006, 3:08pm UTC](https://www.ruby-forum.com/t/rjs/102384/4 "2006-02-08T15:08:19Z")

</div>

Thank you for your answer  
I have the book in front of me (the pdf of course)  
I did not see this \<\< method, but just found it in the last version of  
the doc ! Great !

For the delay, i cannot get it working more than once.  
I want to execute an effect for each item in an array and each time  
apply the same delay… I am going to play with that \<\< thing.

Thanks a lot 🙂

---

<div class="post-metadata">

**Author:** ![sucrenoir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@sucrenoir](https://www.ruby-forum.com/u/sucrenoir)\
**Post date:** [February 8, 2006, 4:56pm UTC](https://www.ruby-forum.com/t/rjs/102384/5 "2006-02-08T16:56:51Z")

</div>

I found a solution that is working great :

i = 0  
@hp.each{ |hp|  
page.delay(i) do  
page.visual\_effect :Fade, ‘scoop\_’+hp.id.to\_s  
i+=1  
end  
}

Thx for your help

---

<div class="post-metadata">

**Author:** ![sucrenoir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e68b1a/32.png) [@sucrenoir](https://www.ruby-forum.com/u/sucrenoir)\
**Post date:** [February 8, 2006, 5:05pm UTC](https://www.ruby-forum.com/t/rjs/102384/6 "2006-02-08T17:05:20Z")

</div>

On 2/8/06, jm goom [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I found a solution that is working great :
> 
> i = 0  
> @hp.each{ |hp|  
> page.delay(i) do  
> page.visual\_effect :Fade, ‘scoop\_’+hp.id.to\_s  
> i+=1  
> end  
> }

More ruby-like:

@hp.each\_with\_index do |hp, index|  
page.delay(index) do  
page.visual\_effect :Fade, “scoop\_#{ hp.id }”  
end  
end
