Turning off RJS debugging on a per controller/action basis
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
Good find, Eric. This will definitely come in handy.
I like the new design
Thanks for sharing this! I ended up making it a private method (I chose to call it
#temporarily_disable_rjs_debug) and throwing#yieldin the middle. I can then wrap my controller action intemporarily_disable_rjs_debug do ...Testing the method was tricky because rjs_debug set to false by default in the test env
Thanks again!