javascriptruby-on-railsangularjsangularjs-templates

angular-rails-templates Failed to load template


I'm trying to get Angular to load a template:

var app = angular.module("myApp", ['templates'])

and my html:

<div ng-app="myApp">
  <div ng-include="'blah.html'"></div>
</div>

But all I get is a 404 Failed to load resource because, Rails tells me, No route matches [GET] "/blah.html". I understand that this is because of the asset pipeline in Rails. blah.html is in /app/assets/javascripts/templates/blah.html and I am using the angular-rails-templates gem to try to solve the problem. So my application.js has:

//= require angular-rails-templates
//= require_tree ./templates

But I'm not having any luck.

The html generated suggests that angular-rails-templates is loading (it has a script /assets/angular-rails-templates....js) but rails is failing to find blah.html

Versions:
rails 4.2.1
angular-rails-templates 0.1.4
angularjs 1.3.15


Solution

  • This turned out to be a sprockets incompatibility (see here and here)

    The short version is:

    1. Add gem 'sprockets', '2.12.3' to your Gemfile
    2. Run bundle update sprockets

    [Update] I'm no expert on this stuff but it does seem that a number of people smarter than I are suggesting using /public/templates. You may want to bear this in mind.