austin entrepreneur

Turning off RJS debugging on a per controller/action basis

Posted in Uncategorized by efalcao on June 10, 2008

FiveRuns TuneUp is a neat profiling tool for developers. Developing this tool also has brought up some interesting challenges. Here is one that I encountered today:

TuneUp injects into the head of the page and does an AJAX call to fill up the actual run data. We noticed that it was running slow and one of the reasons is that in development mode rails wraps RJS in a javascript try/catch block that produces an alert message with the RJS if there is an exception. On a random run, AJAX response size without RJS debug: 82k, with debug: 386k. That’s quite a bit of overhead.

We can’t tell all TuneUp users to manually turn off RJS debugging, so here is how we disable it solely for our one heavy AJAX action in rails version 2 or greater:

def action_name
  debug_rjs = response.template.debug_rjs
  response.template.debug_rjs = false
  ...
  response.template.debug_rjs = debug_rjs
end

It’s trivial, but it took a little bit of digging through the rails source to find out how to get to this from inside the controller, so I hope it’ll save others some time

Advertisements

3 Responses

Subscribe to comments with RSS.

  1. brian said, on June 11, 2008 at 3:01 am

    Good find, Eric. This will definitely come in handy.

  2. Howard Rauscher said, on June 11, 2008 at 12:58 pm

    I like the new design

  3. Tom said, on June 14, 2008 at 1:58 pm

    Thanks for sharing this! I ended up making it a private method (I chose to call it #temporarily_disable_rjs_debug) and throwing #yield in the middle. I can then wrap my controller action in temporarily_disable_rjs_debug do ...

    Testing the method was tricky because rjs_debug set to false by default in the test env 😉

    Thanks again!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: