공식 문서 에서 다음 예를 고려하십시오 .
class ApplicationController < ActionController::Base
before_action :require_login
private
def require_login
unless logged_in?
flash[:error] = "You must be logged in to access this section"
redirect_to new_login_url # halts request cycle
end
end
end
redirect_to
API 전용 응용 프로그램 에서는 의미가 없습니다 . 필터가있는 API 전용 애플리케이션에서 요청주기를 중지하고 사용자 정의 json 또는 401 코드로 응답하려면 어떻게해야합니까?
렌더링 만하면 충분합니다.
class PostsController < ActionController::API # or ApplicationController
before_action :halt_request
def index
render json: "bravemaster"
end
private
def halt_request
if params[:halt]
render json: "I stopped"
end
end
end
ActionController가 콜백에 설정된 응답 본문을 감지하면 반환합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다