Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 314
jcuenod Avatar asked Dec 06 '22 22:12

jcuenod


2 Answers

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.

like image 116
jcuenod Avatar answered Dec 08 '22 12:12

jcuenod


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'])
like image 45
Kyle Avatar answered Dec 08 '22 12:12

Kyle