Forum: Ruby on Rails RJS head scratcher

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.
3fdda7e032a5619199486d05b506ced4?d=identicon&s=25 Brad Daily (bdaily)
on 2006-05-16 20:51
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?
59de94a56fd2c198f33d9515d1c05961?d=identicon&s=25 Tom Mornini (Guest)
on 2006-05-16 21:48
(Received via mailing list)
I think you'll find that the RJS callback is provoking
a Ruby error.

--
-- Tom Mornini
3fdda7e032a5619199486d05b506ced4?d=identicon&s=25 Brad Daily (bdaily)
on 2006-05-16 22:04
Tom Mornini wrote:
> I think you'll find that the RJS callback is provoking
> a Ruby error.
>
> --
> -- Tom Mornini

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.
6076c22b65b36f5d75c30bdcfb2fda85?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2006-05-16 22:26
(Received via mailing list)
On May 16, 2006, at 11:51 AM, Brad Daily wrote:

> new Effect.Highlight("gi_error_row",{duration:20});
>
> Rails@lists.rubyonrails.org
> 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
5d15c6821f3c3054c04b85471824ba7c?d=identicon&s=25 Kevin Olbrich (Guest)
on 2006-05-16 22:29
(Received via mailing list)
On Tuesday, May 16, 2006, at 10:04 PM, Brad Daily wrote:
>
>And I still get this as the response (again this is via Firebug, I get
>--
>Posted via http://www.ruby-forum.com/.
>_______________________________________________
>Rails mailing list
>Rails@lists.rubyonrails.org
>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
3fdda7e032a5619199486d05b506ced4?d=identicon&s=25 Brad Daily (bdaily)
on 2006-05-16 22:39
Kevin Olbrich 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 (?)
5d15c6821f3c3054c04b85471824ba7c?d=identicon&s=25 Kevin Olbrich (Guest)
on 2006-05-16 23:01
(Received via mailing list)
On Tuesday, May 16, 2006, at 10:39 PM, Brad Daily wrote:
>being eval'ed. Here is the generated onclick event...
>Posted via http://www.ruby-forum.com/.
>_______________________________________________
>Rails mailing list
>Rails@lists.rubyonrails.org
>http://lists.rubyonrails.org/mailman/listinfo/rails

Check the content-type of the header...

http://nubyonrails.com/articles/read/313

_Kevin
3fdda7e032a5619199486d05b506ced4?d=identicon&s=25 Brad Daily (bdaily)
on 2006-05-16 23:54
Kevin Olbrich wrote:
>
> Check the content-type of the header...
>
> 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....
This topic is locked and can not be replied to.