# RJS and javascript objects problem

**URL:** <https://www.ruby-forum.com/t/rjs-and-javascript-objects-problem/72840>\
**Category:** Rails\
**Created:** [October 19, 2006, 10:24am UTC](https://www.ruby-forum.com/t/rjs-and-javascript-objects-problem/72840 "2006-10-19T10:24:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![franee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/b5a626/32.png) [@franee](https://www.ruby-forum.com/u/franee)\
**Post date:** [October 19, 2006, 10:24am UTC](https://www.ruby-forum.com/t/rjs-and-javascript-objects-problem/72840/1 "2006-10-19T10:24:12Z")

</div>

Hi,

I’ve got a js object on my page named appts which has a method render().  
My problem is when i use RJS to call “appts.render()”. it doesn’t do  
anything at all. There are no errors also displayed.

here is my rjs code:

page \<\< “appts.render(‘BG’,0);”

help would be much appreciated:)

thanks

---

<div class="post-metadata">

**Author:** ![franee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/b5a626/32.png) [@franee](https://www.ruby-forum.com/u/franee)\
**Post date:** [October 19, 2006, 11:00am UTC](https://www.ruby-forum.com/t/rjs-and-javascript-objects-problem/72840/2 "2006-10-19T11:00:39Z")

</div>

On 19 October 2006 12:24, franee – wrote:

> I’ve got a js object on my page named appts which has a method render().  
> My problem is when i use RJS to call “appts.render()”. it doesn’t do  
> anything at all. There are no errors also displayed.
> 
> here is my rjs code:
> 
> page \<\< “appts.render(‘BG’,0);”  
> Here is the problem resolution sequence:

1. Turn on browser’s javascript debugging (e.g. in Firefox take a look  
at  
javascript console or install a powerful FireBug extension). You’ll see  
all  
the javascript errors.
2. Examine javascript code that is generated by RJS template. Make sure  
that  
it contains no errors (you can view RJS response in FireBug’s console).
3. Make sure that the RJS response is properly evaled. E.g. in  
Ajax.Request  
there should be evalScripts options set to true.
4. Make sure that you don’t overwrite RJS response’s content type and it  
is  
equal to “text/javascript” (you can view RJS response in FireBug’s  
console).

Hope that helps

---

<div class="post-metadata">

**Author:** ![franee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/b5a626/32.png) [@franee](https://www.ruby-forum.com/u/franee)\
**Post date:** [October 19, 2006, 12:19pm UTC](https://www.ruby-forum.com/t/rjs-and-javascript-objects-problem/72840/3 "2006-10-19T12:19:33Z")

</div>

Maxim K. wrote:

> On 19 October 2006 12:24, franee – wrote:
> 
> > I’ve got a js object on my page named appts which has a method render().  
> > My problem is when i use RJS to call “appts.render()”. it doesn’t do  
> > anything at all. There are no errors also displayed.
> > 
> > here is my rjs code:
> > 
> > page \<\< “appts.render(‘BG’,0);”  
> > Here is the problem resolution sequence:
> 
> 1. Turn on browser’s javascript debugging (e.g. in Firefox take a look  
> at  
> javascript console or install a powerful FireBug extension). You’ll see  
> all  
> the javascript errors.
> 2. Examine javascript code that is generated by RJS template. Make sure  
> that  
> it contains no errors (you can view RJS response in FireBug’s console).
> 3. Make sure that the RJS response is properly evaled. E.g. in  
> Ajax.Request  
> there should be evalScripts options set to true.
> 4. Make sure that you don’t overwrite RJS response’s content type and it  
> is  
> equal to “text/javascript” (you can view RJS response in FireBug’s  
> console).
> 
> Hope that helps

I had already 1-4 covered. Here is the actual code that was spit on the  
debugger:

try {  
appts.render(‘BG’,0);  
} catch (e) { alert(‘RJS error:\n\n’ + e.toString());  
appts.render(‘BG’,0);’); throw e }

There is no exception when this gets executed but the object doesn’t do  
anything. when i do --\> page \<\< “alert(appts);”, i get this --\> [object  
Object]

any more ideas?

---

<div class="post-metadata">

**Author:** ![franee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/b5a626/32.png) [@franee](https://www.ruby-forum.com/u/franee)\
**Post date:** [October 19, 2006, 12:44pm UTC](https://www.ruby-forum.com/t/rjs-and-javascript-objects-problem/72840/4 "2006-10-19T12:44:30Z")

</div>

On 19 October 2006 14:19, franee – wrote:

> Object]
> 
> any more ideas?

1. Try putting alert inside render() method to see if it actually get  
execute.  
If it is, then the problem is in your code, otherwise
2. Try exploring all “appts”'s object properties:

function inspect(o) {  
var result = “Object “+o+” {\n”;  
for(attr in o) {  
result += “”+attr+" = “+o[attr]+”\n";  
}  
result += “}\n”;  
return result;  
}

Put this function into some place from where it could be loaded before  
RJS  
call (e.g. RAILS\_ROOT/public/javascripts/application.js if you use  
javascript\_include\_tag :defaults) and then in RJS do "page  
\<\< “alert(inspect(appts));”

It might be that you’ve got wrong object.

---

<div class="post-metadata">

**Author:** ![franee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/b5a626/32.png) [@franee](https://www.ruby-forum.com/u/franee)\
**Post date:** [October 19, 2006, 4:48pm UTC](https://www.ruby-forum.com/t/rjs-and-javascript-objects-problem/72840/5 "2006-10-19T16:48:51Z")

</div>

Maxim K. wrote:

> On 19 October 2006 14:19, franee – wrote:
> 
> > Object]
> > 
> > any more ideas?
> 
> 1. Try putting alert inside render() method to see if it actually get  
> execute.  
> If it is, then the problem is in your code, otherwise
> 2. Try exploring all “appts”'s object properties:
> 
> function inspect(o) {  
> var result = “Object “+o+” {\n”;  
> for(attr in o) {  
> result += “”+attr+" = “+o[attr]+”\n";  
> }  
> result += “}\n”;  
> return result;  
> }
> 
> Put this function into some place from where it could be loaded before  
> RJS  
> call (e.g. RAILS\_ROOT/public/javascripts/application.js if you use  
> javascript\_include\_tag :defaults) and then in RJS do "page  
> \<\< “alert(inspect(appts));”
> 
> It might be that you’ve got wrong object.

Thanks for the info. I think there’s something wrong with the js object  
or with RJS itself with complex objects. Its a pretty complex one which  
has multiple objects inside it.

appts contains an array of appointment objects. each appointment object  
also contains a hash of measurement objects.

when i call this on the page --\>

document.write(inspect(appts.appts[1].mds[‘BG’]));

it writes the contents of the object to the screen.  
but when i call the same thing inside the rjs template, it says Object  
undefined. pretty weird.
