# RJS head scratcher

**URL:** <https://www.ruby-forum.com/t/rjs-head-scratcher/60699>\
**Category:** Rails\
**Created:** [May 16, 2006, 8:51pm UTC](https://www.ruby-forum.com/t/rjs-head-scratcher/60699 "2006-05-16T20:51:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bdaily](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ed8c4c/32.png) [@bdaily](https://www.ruby-forum.com/u/bdaily)\
**Post date:** [May 16, 2006, 8:51pm UTC](https://www.ruby-forum.com/t/rjs-head-scratcher/60699/1 "2006-05-16T20:51:44Z")

</div>

I’ve been joyfully using RJS in a lot of our work lately, with no issues  
whatsoever. However, I am porting an application to RJS templates that  
we’ve had for a while, and having some issues.

When I use Firebug to see what is going on, the response comes back like  
this:

try {  
new Effect.Highlight(“gi\_error\_row”,{duration:20});  
} catch (e) { alert(‘RJS error:\n\n’ + e.toString()); alert(‘new  
Effect.Highlight(“gi\_error\_row”,{duration:20});’); throw e }

I know from looking at my working apps with RJS that the response should  
not be wrapped in a try/catch statement. Most of my googling has turned  
up suggestions to make sure your rails project is up to date, but mine  
is (1.1.2) and the javascripts have also been updated (prototype  
1.5.0\_rc0). It was updated via the rake rails:update command…

When I create a new app on my system to test out things, RJS works fine.  
There must be some cruft from pre 1.1 rails in my project somewhere, but  
where?

---

<div class="post-metadata">

**Author:** ![bdaily](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ed8c4c/32.png) [@bdaily](https://www.ruby-forum.com/u/bdaily)\
**Post date:** [May 16, 2006, 9:48pm UTC](https://www.ruby-forum.com/t/rjs-head-scratcher/60699/2 "2006-05-16T21:48:43Z")

</div>

I think you’ll find that the RJS callback is provoking  
a Ruby error.

–  
– Tom M.

---

<div class="post-metadata">

**Author:** ![bdaily](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ed8c4c/32.png) [@bdaily](https://www.ruby-forum.com/u/bdaily)\
**Post date:** [May 16, 2006, 10:04pm UTC](https://www.ruby-forum.com/t/rjs-head-scratcher/60699/3 "2006-05-16T22:04:33Z")

</div>

Tom M. wrote:

> I think you’ll find that the RJS callback is provoking  
> a Ruby error.
> 
> –  
> – Tom M.

I don’t think so. I just tried some super simple code:

# Controller

def create

# Nothing here yet

end

# create.rjs

page.alert “Hi”

# View

link\_to\_remote “Go”, :url =\> { :action =\> ‘create’ }

And I still get this as the response (again this is via Firebug, I get  
no response whatsoever in the browser window):  
try {  
alert(“Hi”);  
} catch (e) { alert(‘RJS error:\n\n’ + e.toString());  
alert(‘alert(“Hi”);’); throw e }

But if I throw that very same code into a new project, everything works  
as expected.

---

<div class="post-metadata">

**Author:** ![bdaily](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ed8c4c/32.png) [@bdaily](https://www.ruby-forum.com/u/bdaily)\
**Post date:** [May 16, 2006, 10:26pm UTC](https://www.ruby-forum.com/t/rjs-head-scratcher/60699/4 "2006-05-16T22:26:39Z")

</div>

On May 16, 2006, at 11:51 AM, Brad D. wrote:

> new Effect.Highlight(“gi\_error\_row”,{duration:20});
> 
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

Brad-

```
I think the try catch statements are only added in development mode.

```

So in your production sites you probably aren’t seeing it. Try  
launching this current app in production mode and see what happens.

-Ezra

---

<div class="post-metadata">

**Author:** ![bdaily](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ed8c4c/32.png) [@bdaily](https://www.ruby-forum.com/u/bdaily)\
**Post date:** [May 16, 2006, 10:29pm UTC](https://www.ruby-forum.com/t/rjs-head-scratcher/60699/5 "2006-05-16T22:29:48Z")

</div>

On Tuesday, May 16, 2006, at 10:04 PM, Brad D. wrote:

> ## And I still get this as the response (again this is via Firebug, I get
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

Look in your environments/development.rb file, you may see a line like…

config.action\_view.debug\_rjs = true

try turning that off and see if the ‘try’ goes away.

\_Kevin

---

<div class="post-metadata">

**Author:** ![bdaily](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ed8c4c/32.png) [@bdaily](https://www.ruby-forum.com/u/bdaily)\
**Post date:** [May 16, 2006, 10:39pm UTC](https://www.ruby-forum.com/t/rjs-head-scratcher/60699/6 "2006-05-16T22:39:32Z")

</div>

Kevin O. wrote:

> config.action\_view.debug\_rjs = true
> 
> try turning that off and see if the ‘try’ goes away.
> 
> \_Kevin

Yep, that takes away the try/catch stuff, and returns the correct JS  
command. Still nothing in the browser, so obviously the scripts aren’t  
being eval’ed. Here is the generated onclick event…

onclick=“new Ajax.Request(’/request/create’, {asynchronous:true,  
evalScripts:true}); return false;”

Looks good to me (?)

---

<div class="post-metadata">

**Author:** ![bdaily](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ed8c4c/32.png) [@bdaily](https://www.ruby-forum.com/u/bdaily)\
**Post date:** [May 16, 2006, 11:54pm UTC](https://www.ruby-forum.com/t/rjs-head-scratcher/60699/7 "2006-05-16T23:54:13Z")

</div>

Kevin O. wrote:

> Check the content-type of the header…
> 
> [http://nubyonrails.com/articles/read/313](http://nubyonrails.com/articles/read/313)
> 
> \_Kevin

Ahhh…that led me in the right direction. I was using the utf lib and  
had completely forgot about it setting the content-type. I took that  
part out of the utf lib, and used the after filter as described in the  
link above. Thanks all for helping me troubleshoot…

---

<div class="post-metadata">

**Author:** ![bdaily](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ed8c4c/32.png) [@bdaily](https://www.ruby-forum.com/u/bdaily)\
**Post date:** [May 16, 2006, 11:01pm UTC](https://www.ruby-forum.com/t/rjs-head-scratcher/60699/8 "2006-05-16T23:01:36Z")

</div>

On Tuesday, May 16, 2006, at 10:39 PM, Brad D. wrote:

> being eval’ed. Here is the generated onclick event…  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

Check the content-type of the header…

[http://nubyonrails.com/articles/read/313](http://nubyonrails.com/articles/read/313)

\_Kevin
