Angularjs を使用して、Heroku に配置した Rails テスト アプリから JSON を取得しようとしています。以下に、Angular と Rails のコードを示します。
これは、Firebug コンソールに表示されるエラーです。「NetworkError: 404 が見つかりません - http://desolate-earth-2852.herokuapp.com/declarations.json」
これが機能しない理由はありますか?
Angularjs コード
var App = angular.module('App', []);
App.controller('TodoCtrl', function($scope, $http) {
$http.get('http://desolate-earth-2852.herokuapp.com/declarations.json')
.then(function(res){
$scope.todos = res.data;
});
});
Railsコード
def index
@declarations = Declaration.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @declarations }
end
end
ここにルートがあります
Test::Application.routes.draw do
root :to => 'welcome#index'
get "welcome/index"
resources :declarations
end