Starting with Rails 3.1, it provides two things that make working with Backbone templates easier: an asset pipeline and an automatic JST structure (JavaScript Template).
Create a directory in the app/assets folder named templates . This directory is automatically selected by the asset pipeline.
Then specify the files in this directory with the jst extension and the type of the created ejs template (built-in javascript). You can even nest them in directories. For instance:
app/assets/templates/my_template.jst.ejs app/assets/templates/bookmarks/show.jst.ejs
The asset console also allows you to use other template languages, such as the built-in coffeescript, mustache, rudders, etc., simply by changing the file extension (and including any gems needed).
Now, to reference your JST templates in Backbone views, simply use the file name path:
var Bookmark = Backbone.View.extend({ template: JST['bookmarks/show'], render: function() { this.$el.html(this.template(this.model.attributes)); return this; } });
You may need to add this line to your application.js :
Here is a good article that explains all this in a bit more detail: http://www.bigjason.com/blog/precompiled-javascript-templates-rails-3-1
source share