tbatucan's blog

When to use helpers for generating javascript

A practice that I've started doing more of in my Rails application has been using a helper to generate javascript to remove duplication and magic numbers or strings. Primarily the only time I've generated javascript is when I needed to generate the url for an Ajax request or something similar using the url_for{:controller=>'foo', :action=>'bar'}. In the past, most of my javascript was placed in a static javascript file in the javascript library. One of the justifications for this of course is to allow the browser to cache the javascript file.

Subscribe to RSS - tbatucan's blog