Trying to extract information from an action in my controller.
The current state of the action is as follows:
def index
@users = User.all
respond_to do |format|
format.html
format.json { render json: @users }
end
end
This index page is designated as the root in routes.rb
Now, here's a glimpse of my AngularJs controller where I'm attempting to retrieve the data:
@test.controller 'TestCtrl', ['$scope', '$location', '$http', ($scope, $location, $http) ->
$scope.data = []
$http.get('/')
.success (data) =>
$scope.data = data
console.log($scope.data)
.error (data) ->
console.log('error!')
]
Upon loading the root page, only the entire page loads in the Javascript console log.
Am I overlooking any necessary steps to ensure that the action index
responds in json for my AngularJs controller?
Server log:
Started GET "/" for 127.0.0.1 at 2014-11-28 18:02:26 +0200
Processing by VisitorsController#index as HTML
(0.4ms) SELECT COUNT(*) FROM "users"
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1
(2.1ms) SELECT COUNT(*) FROM "users" INNER JOIN "relationships" ON "users"."id" = "relationships"."followed_id" WHERE "relationships"."follower_id" = $1 [["follower_id", 1]]
(0.2ms) SELECT COUNT(*) FROM "users" INNER JOIN "relationships" ON "users"."id" = "relationships"."follower_id" WHERE "relationships"."followed_id" = $1 [["followed_id", 1]]
Rendered users/_stats.html.erb (4.8ms)
Rendered visitors/index.html.erb within layouts/application (6.9ms)
Rendered layouts/_navigation_links.html.erb (0.3ms)
Rendered layouts/_navigation.html.erb (0.7ms)
Rendered layouts/_messages.html.erb (0.0ms)
Completed 200 OK in 137ms (Views: 134.0ms | ActiveRecord: 2.9ms)