2015-09-14 200 views
0

我试图渲染采用了棱角分明我的所有用户的列表,但我得到一个500内部服务器错误,当我尝试加载users.json的getJSON 500(内部服务器错误)

这是我的服务, angular.module( '用户')

.factory('UsersFactory', ['$http', function($http) { 
    return { 
     loadUsers: function() { 
     return $http.get('/users.json'); 
     } 
    }; 
    }]) 

这是控制器, angular.module( '用户',[])

.controller('UserListCtrl', [ 

    '$scope', 'UsersFactory', 
    function ($scope, UsersFactory) { 

     var init = function(){ 
     UsersFactory.loadUsers().then(function(response) { 
      $scope.users = response.data; 
      console.log ($scope.users) 
     }); 
     } 
     init(); 

    } 
    ]); 

而我尝试渲染用户的模板,

Users 
.user_container{"ng-repeat" => "user in user"} 
    {{ user.name }} 

而这是错误在我的rails服务器输出,

Completed 500 Internal Server Error in 27ms (ActiveRecord: 22.9ms) 

ActionView::MissingTemplate (Missing template users/index, application/index with {:locale=>[:en], :formats=>[:json], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :haml, :jbuilder]}. Searched in: 
    * "/home/alucardu/sites/movieseat/app/views" 
    * "/home/alucardu/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/devise-3.5.2/app/views" 
): 
+0

错误与您的服务器端代码和角码有关,因此您最好将服务器端代码并​​从问题 – harishr

+0

@entre中移除js代码感谢您的输入。使感觉。你能帮我设置控制器和路线来解决这个问题吗? –

+0

抱歉,但我不知道ror如此无法帮助 – harishr

回答

0

通过把这个,

@users = User.all 
    respond_with(@users) 

在我user_controller.rb这

resources :users, only: [:index, :show] 

在我的routes.rb我得到它的工作。