I'm new to angular and I'm trying to add it to one of my Rails projects. I'm using the angular-rails gem. I want to list users using $resource.query() and I'm getting the following error:
Error: [$resource:badcfg] Error in resource configuration. Expected response to contain an array but got an object
When I check localhost:3000/users.json it's showing an array of user objects, so the response should be in the correct format. Here's what I have:
In app/assets/javascript/users.js.coffee:
app = angular.module("Volunteers", ["ngResource"])
app.factory "User", ["$resource", ($resource) ->
$resource("/users/:id", {id: "@id"}, {update: {method: "PUT"}})
]
@UserCtrl = ["$scope", "User", ($scope, User) ->
$scope.users = User.query()
]
In app/views/users/index.html:
<div ng-controller="UserCtrl">
<ul>
<li ng-repeat="user in users">
{{user.name}}
</li>
</ul>
</div>
And in the users_controller:
class UsersController < ApplicationController
respond_to :json, :html
def index
respond_with User.all
end