Currently, I am experimenting with Angular routing within my Ruby on Rails application.
The issue arises when I navigate to a specific route, such as '/'
, and have an Angular routing setup to load a template from a designated directory. This triggers an error in my Rails server:
Started GET "/templates/index.html.erb" for 127.0.0.1 at 2014-12-02 18:03:39 +0200
ActionController::RoutingError (No route matches [GET] "/templates/index.html.erb"):
It seems that instead of trying to fetch the file from the specified folder, it attempts to append the angular route path to the URL, resulting in a request?
For instance, if I replace the templateUrl:
with /users
, which is a valid route returning HTML in my app, it successfully navigates there. However, this behavior is not what I desire.
My intention is for Angular to swap out the html template in my ng-view upon entering the designated route.
Below is my Angular routing code:
App = angular.module("App", ['ngRoute', 'growlNotifications'])
App.config ($httpProvider) ->
authToken = $("meta[name=\"csrf-token\"]").attr("content")
$httpProvider.defaults.headers.common["X-CSRF-TOKEN"] = authToken
App.config ($routeProvider, $locationProvider) ->
$locationProvider.html5Mode true
$routeProvider
.when '/',
templateUrl: 'templates/index.html.erb',
controller: 'VisitorsCtrl'
.when '/users',
templateUrl: '../../views/users/index.html.erb',
controller: 'UsersCtrl'
.otherwise redirectTo: "/"
In my application.html.erb
, I have set the base href
to '/'
Currently, my templates are located at:
app/assets/javascripts/angular/templates
and the routing is defined within the angular
folder
What could potentially be causing this issue?