Forum: Ruby on Rails Is a javascript object accessible in the .rjs file (AJAX) ?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ad745a3a6bdc249a7b34a0b6f5c8d5ec?d=identicon&s=25 LuCa (Guest)
on 2007-04-09 17:24
Hi All

In my rhtml file I create a javascript object like

    function onLoad() {
        js_obj = new Pkgname.ClassName(<%= my_tabs.to_json %>)

This 'js_obj' is the javascript object which use all the time in this
page to hide/show/change stuff depending on the users actions. At some
point the user can click a button, which starts an AJAX
request(button_to_function), which will update, lets say, tab 3. This
means: I need to do the AJAX call and afterwards chnage to tab 3. I
hoped that I could access to 'js_obj' in my .rjs file so I could do
something like


This should change to tab 3, but doesn't work. Hopefully I have the
syntax wrong, do I ?

If this is not possible is there a way I can perform an action after the
ajax request is finished with a button_to_function request ?

D7c511ce5025d37b8c6bd9134e0f2bd9?d=identicon&s=25 Thorsten (Guest)
on 2007-04-09 17:55
(Received via mailing list)
i may be wrong, but i think i read a couple of times that you can do
this in an rjs file:

page << "js_obj.showTabByIndex(3)"

i think you can "feed" any JavaScript code into the page object like
this, and it wll be sent back to the browser.
could be wrong though, give it a try.
Ad745a3a6bdc249a7b34a0b6f5c8d5ec?d=identicon&s=25 LuCa (Guest)
on 2007-04-09 18:21
that works perfect, thnx

Just for those interested, I noticed that the same thing can also be
done using

    :complte => ""

inside the button_to_function call (this is on the client side)

This topic is locked and can not be replied to.