2013-11-25 3 views
0

각도로 레일을 사용하여 게시물의 내용을 나열하려하지만 완전히 멈췄습니다.각도와 레일로 '표시'동작

내 컨트롤러 :

def show 
    @post = Post.find(params[:id]) 

    respond_to do |format| 
     format.html 
     format.json { render json: @post } 
    end 
    end 

'각도에서 안녕하세요'그러나 나머지는 나에게 오류 제공, 벌금 보여주고있다 :

GET http://localhost:3000/posts/show 500 (Internal Server Error) 

var myApp = angular.module('myApp', ['ngResource']); 

myApp.controller('categoryController', ['$scope', 'Post',function($scope, Post) { 
    $scope.heading = "Hello from angular"; 
    $scope.post = Post.query(); 
}]) 

myApp.factory('Post', ['$resource', function($resource) { 
    return $resource('/posts/:id', { id: "@id" }); 
}]) 

게시물 컨트롤러를 레일 이 나쁜 소년을 길을 안내하는 올바른 방법을 알아낼 수 없습니다. 어떤 도움이 입력

편집 주셔서 감사합니다 : routes.rb를

resources :users 

    resources :hubs, shallow: true do 
    resources :posts, shallow: true 
    resources :comments, shallow: true do 
     collection {post :sort} 
    end 
    end 
+0

당신이'routes.rb'의 내용을 게시 할 수 호출? – zeantsoi

+0

@zeantsoi 확실한 것! –

답변

1

당신이 표시되는 오류는 500이 아니라 404 나는이 그만큼 라우팅 문제라고 생각하지 않습니다이다 코드에서 무언가 처리되지 않은 예외가 발생하는 것 같습니다.

Post.query()를 호출하면 show 메서드가 아닌 인덱스 메서드로 전달되는 쿼리를 만들어야하기 때문에 약간 혼동 스럽습니다.

show 메소드로 연결하려는 경우 Post.get ({id : someID})을 원할 수 있습니다. 그렇지 않으면 인덱스 메소드는 어떻게 생겼을까요?

+0

잘 색인 방법이 없습니다. 저는 Angular를 실험하고 있었으며 별도의 프로그램 방법 만 보여 주려고했습니다. –

+0

@DenisG Post.query()를 get() 호출로 변경하려고 시도 했습니까? – mfollett

0

query() 메서드는 게시물 ID를 전달하지 않고 GET 요청을 보냅니다. 그래서 URL이 불완전하고 500 오류가 발생합니다.

this article에 끝났다처럼 공장을 정의하고

$scope.post = Post.show(id);