【发布时间】:2015-04-03 00:55:24
【问题描述】:
我正在尝试使用 Angular 的 $resource 检索 Rails 记录的集合,但是当我尝试在视图中呈现这些记录时,我不断得到一个空数组。
posts_controller.rb
def index
@posts = current_user.author.posts.limit(25)
end
app.js.coffee
app = angular.module('app', ['ngResource'])
app.factory 'Posts', ($resource) ->
$resource '/posts/:id', {}, query:
method: 'GET'
isArray: true
responseType: 'json'
app.controller 'PostsCtrl', ($scope, Posts) ->
$scope.posts = Posts.query()
在控制台中,我看到 $resolved 是错误的,所以我不确定问题是否与访问 json 数据本身或 $promise 有关
【问题讨论】:
标签: ruby-on-rails angularjs angular-resource