:layout => false

Thursday 11/27/2008  –  Category: Merb

I ran into a strange behavior when trying to use setInterval in JS to make an AJAX request every n seconds.  I had the timer in the $(document).ready(function() { } in the head of my application layout file.

There would be strange behavior with the timer--every interval would be twice as fast as the previous, and the browser would quickly become unresponsive and crash.

I initially thought it was a Firefox bug so I wasted sometime googling setInterval but it turns out the AJAX request was rendering the view with the layout, thus creating another timer on each request.  Stupid.

Setting :layout => false on the offending action made everything play nice.  Moral of the story: don't forget to exclude your layouts for AJAX actions.

Leave a Reply