Most rails 3.1 tutorials regarding the asset pipeline and javascript templating lead me to believe that the asset pipeline will pick up any *.jst files and slap them into a JST variable that's available to your *.js files. However, I'm currently stumped with the following error when I try to load a *.jst template:
Uncaught ReferenceError: JST is not defined
Any pointers?
if you are using a require line like
//= require_tree ../templates
make sure that line is above the line that includes whatever file is giving you the error.
The JST variable seems to get set if you correctly include the javascript template items in your app/assets/application.js
file so they can be included via the asset pipeline:
//= require templates/your_template.jst
Then include the javascript template in your corresponding rails views (using haml):
- content_for :javascripts do
= javascript_include_tag "templates/your_template"
All the other answers are getting at this, but to clarify...
JST is not defined by sprockets unless one or more .jst files have been required in the manifest.
So even if you have //= require_tree ../templates
in your manifest, JST will still be undefined until you create at least one .jst file in the templates directory.
Also be sure to include the EJS gem. If you've included backbone-on-rails, you have it already.
Sounds like you need the EJS Gem, which is included if you use the rails-backbone Gem.
Then you just create a file like app/asset/javascripts/foobar.jst.ejs and it can be rendered by calling
JST['foobar']()
Hope that answers your question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With