【发布时间】:2013-10-25 04:54:18
【问题描述】:
我正在尝试使用 Angularjs 从我放在 Heroku 上的 Rails 测试应用程序中获取 JSON。您将在下面找到我的 Angular 和 Rails 代码。
这是我在 Firebug 控制台中遇到的错误。 "NetworkError: 404 Not Found - 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;
});
});
导轨代码
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
【问题讨论】:
-
你有这样定义的路由吗:
resources :declarations? -
是的,发布你的 routes.rb 代码
-
我已经添加了路线。我已经有了资源:声明。
-
奇怪的是你得到了 404。你是否也从同一个 herokuapp 运行角度代码?你能指定 Angular 代码运行的 url 吗?
-
@Manuel van Rijn。我在我的桌面上本地运行 Angular 代码
标签: javascript ruby-on-rails json angularjs heroku