2016-06-07 2 views
0

안녕 원하는 값을 반환하지,하지만 난 "안녕하세요"내 레일 API를 내가 API를 쓰기 위해 노력하고있어

컨트롤러 반환하지 않는 컨트롤러에 문제가 있어요 :

class ApisController < ApplicationController 
    before_action :set_api, only: [:show, :edit, :update, :destroy] 

    # GET /apis 
    # GET /apis.json 

    def alertdump 

    respond_to do |format| 
     format.html { render html: 'hi' } 
     format.json { render json: "hi" } 
    end 
    end 

경로를 :

resources :apis do 
    collection do 
     post 'alertdump/:fullalert', :action=> 'alertdump' 
    end 
    end 

내가 대신지고있어이

{"id":1,"created_at":"2016-06-07T15:05:17.897Z","updated_at":"2016-06-07T15:05:17.897Z"} 
(모델 'API'의 첫 번째 요소 인)
+0

어떤 요청을 사용하고 경로를 어떻게 정의합니까? –

답변

0

api 용 코드를 작성한다고 말하면서 html 요청에 응답 할 필요가 없으며 json 응답을 보내려 시도 할 수 있습니다.

class ApisController < ApplicationController 
    before_action :set_api, only: [:show, :edit, :update, :destroy] 

    def alertdump 
    render :json => 'Hi' 
    end 
end 
+0

여전히 동일한 응답을 받음 { "id": 1, "created_at": "2016-06-07T15 : 05 : 17.897Z", "updated_at": "2016-06-07T15 : 05 : 17.897Z"} –

+0

전체 컨트롤러 파일을 넣을 수 있습니까? –

관련 문제