0
라우팅 오류를 생성 한 URL을 캡처하려고합니다. 최종 목표는 이전 사이트 (도메인 변경)에 존재하는지 확인하고 이전 사이트로 리디렉션하는 경우 URL을 확인하여 도메인을 변경하는 것입니다. 여기 내가 가진 일이있다.레일 : ActionController :: RoutingError를 생성 한 URL을 캡처하십시오.
unless Rails.application.config.consider_all_requests_local
rescue_from Exception, with: :render_500
rescue_from ActionController::RoutingError, with: :check_old_site
rescue_from ActionController::UnknownController, with: :render_404
rescue_from ActionController::UnknownAction, with: :render_404
rescue_from ActiveRecord::RecordNotFound, with: :render_404
end
private
def check_old_site(exception)
#Need to edit the URL but I need access to before I can write the code to modify
captured_and_modified_url = ???
case Net::HTTP.get_response(URI.parse(captured_and_modified_url))
when Net::HTTPSuccess then redirect_to captured_and_modified_url
else render_404(exception)
end
end
def render_404(exception)
@not_found_path = exception.message
respond_to do |format|
format.html { render template: 'errors/error_404', layout: 'layouts/application', status: 404 }
format.all { render nothing: true, status: 404 }
end
end
그래서이 질문에 대한 그냥 404 오류로받은 URL에 싶어. 어떤 도움을 주셔서 감사합니다.