Forum: Ruby on Rails [RJS] How can i reload a script.

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.
83c8cca11558f32207645ca270ae8475?d=identicon&s=25 sishen (Guest)
on 2007-05-24 05:30
(Received via mailing list)
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" %>

<div id="preview">
   <%= render :partial => "script", :object => @script %>
</div>
}}}

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

@script is a variable whose content is a javascript code, like
"<script type="text/javascript" src="http://xxx?title=xxxx"></script>"

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>") } .........."   But i can't see
the effect in my page.

i don't know why it didn't work well. Thanks for your help.
40db9e75b3f5899258e3bdc0c9210154?d=identicon&s=25 Conrad Taylor (Guest)
on 2007-05-24 06:02
(Received via mailing list)
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
83c8cca11558f32207645ca270ae8475?d=identicon&s=25 sishen (Guest)
on 2007-05-24 06:22
(Received via mailing list)
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.
7a03066e8719f4d938bf622351ce4e7b?d=identicon&s=25 unknown (Guest)
on 2007-05-24 06:23
(Received via mailing list)
dear sender,
i´m out of the office until may 29th.
your email will not be forwarded.
for urgent stuff please contact joern@fork.de
kind regards,
alexander
This topic is locked and can not be replied to.