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
This turned out to be a sprockets incompatibility (see here and here)
The short version is:
gem 'sprockets', '2.12.3'
to your Gemfilebundle 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.
I had a similar issue - In my haste, I neglected to fully read the directions, and missed step 3.
Adding a Dependency in the Angular Application Module solved it for me, and the templates are served through the asset pipeline...
//= require angular-rails-templates
//= require_tree .
angular.module('d-angular', ['templates'])
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