backbone.jsunderscore.jsjammit

How to use Ruby code inside JST files?


I am using Jammit to package my assets. One of the things it does well is package files with .jst extension and make them available in window.jst namespace in the browser. However, I've been looking for a way to make those templates dynamic, and I'm not sure how to do that or if it's even possible.

What alternatives do I have if I cannot make JST files dynamic?


Solution

  • As far as I can tell with Rails 3.0 it isn't possible. Jammit assumes the JST files are JavaScript files. Maybe in later versions they may add the ability. But I wouldn't count on it happening any time soon.

    If you are able to upgrade to Rails 3.1 you can replace Jammit with the Asset Pipeline that allows you to run it through ERB or what ever language you want before it ends up as a JST file.

    Kliment Mamykin made a walkthrough to upgrade from Rails 3.0 to Rails 3.1.rc4 with Asset Pipeline enabled. http://mamykin.com/2011/07/03/upgrading-to-rails31-rc4.html