# \[RJS\] How can i reload a script

**URL:** <https://www.ruby-forum.com/t/rjs-how-can-i-reload-a-script/104942>\
**Category:** Rails\
**Created:** [May 24, 2007, 5:30am UTC](https://www.ruby-forum.com/t/rjs-how-can-i-reload-a-script/104942 "2007-05-24T05:30:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sishen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5a626/32.png) [@sishen](https://www.ruby-forum.com/u/sishen)\
**Post date:** [May 24, 2007, 5:30am UTC](https://www.ruby-forum.com/t/rjs-how-can-i-reload-a-script/104942/1 "2007-05-24T05:30:51Z")

</div>

I met a problem about reloading a script.

Below is the source code.

display.rhtml:  
{{{  
\<%= text\_field\_tag :title %\>  
\<%= observe\_field :title, :frequency =\> 0.5, :url =\> { :action =\>  
“update” }, :with =\> “title” %\>

 \<%= render :partial =\> "script", :object =\> @script %\>
}}}

\_script.rhtml  
{{{  
\<%= @script %\>  
}}}

@script is a variable whose content is a javascript code, like  
“”

preview\_controller.rb:  
{{{  
def update  
title = params[:title]  
@script = xxxxxx ← regenerate the script due to the title  
change.

```
render :update do |page|
   page.replace "preview", :parital => "script", :object =>

```

@script  
end  
end  
}}}

I can see the display of script at first. But when i change title, it  
just disappeared. I saw the response through firebug, which is like  
"try { Element.update(“preview”, “\<script type="text/javascript" src=  
"[http://xxx?title=xxxx\“\>\</script\>”](http://xxx?title=xxxx%5C%22%3E%3C/script%3E%22)) } …” But i can’t see  
the effect in my page.

i don’t know why it didn’t work well. Thanks for your help.

---

<div class="post-metadata">

**Author:** ![sishen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5a626/32.png) [@sishen](https://www.ruby-forum.com/u/sishen)\
**Post date:** [May 24, 2007, 6:02am UTC](https://www.ruby-forum.com/t/rjs-how-can-i-reload-a-script/104942/2 "2007-05-24T06:02:53Z")

</div>

Hi, I guess that I have had success doing the following:

a) edit the Javascript or RJS  
b) restart webserver or clear your cache

It appears that the Javascript and/or RJS gets cached during server  
runs. Thus, I simply restart the server to clear the cache. This  
doesn’t happen all the time but restarting the server ensures that I’m  
running the latest code in my code base.

Good luck,

-Conrad

---

<div class="post-metadata">

**Author:** ![sishen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5a626/32.png) [@sishen](https://www.ruby-forum.com/u/sishen)\
**Post date:** [May 24, 2007, 6:22am UTC](https://www.ruby-forum.com/t/rjs-how-can-i-reload-a-script/104942/3 "2007-05-24T06:22:54Z")

</div>

Hi. That’s not what i want.

I want to give user a preview of the script result. And the result is  
changed when user input different title.

So, i can’t restart webserver or clear the cache.

---

<div class="post-metadata">

**Author:** ![sishen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5a626/32.png) [@sishen](https://www.ruby-forum.com/u/sishen)\
**Post date:** [May 24, 2007, 6:23am UTC](https://www.ruby-forum.com/t/rjs-how-can-i-reload-a-script/104942/4 "2007-05-24T06:23:55Z")

</div>

dear sender,  
i´m out of the office until may 29th.  
your email will not be forwarded.  
for urgent stuff please contact removed\_email\_address@domain.invalid  
kind regards,  
alexander
