반응형
Javascript 요청에 대한 Rescue_from
나의 Rails 2.3.8 응용 프로그램에서 나는 예외를 위한 rescue_from 코드를 가지고 있었는데, 이것은 Javascript 작업 중에 던져집니다.
rescue_from ::Exception, :with => :show_js_errors
...
def show_js_errors exception
if request.format == :js
flash[:error] = 'some error occured'
render :update do |page|
page.redirect_to({:controller => '/home', :action => :index})
end
else
# use default error handling for non-JS requests
rescue_action_without_handler(exception)
end
end
따라서 Ajax 호출에 오류가 발생하면 사용자에게 오류 메시지가 표시됩니다.레일 3에서는 "without_handler" 메서드가 더 이상 존재하지 않기 때문에 기본 오류 처리를 간단히 호출할 수 없습니다.
갱신하다 도
검색 3시간 만에 올린 글인데, 올린 지 30분 만에 스스로 해결책을 찾았습니다.
예외를 다시 제기하십시오.
사용자가 오류 처리 중이므로 이 예외를 제외하고는 더 이상 처리되지 않습니다.
예외를 다시 제기하십시오.
def show_js_errors exception
if request.format == :js
flash[:error] = 'some error occured'
render :update do |page|
page.redirect_to({:controller => '/home', :action => :index})
end
else
raise # <<
end
end
http://simonecarletti.com/blog/2009/11/re-raise-a-ruby-exception-in-a-rails-rescue_from-statement/ 은 다음과 같이 동의합니다.
rescue_from ActiveRecord::StatementInvalid do |exception| if exception.message =~ /invalid byte sequence for encoding/ rescue_invalid_encoding(exception) else raise end end[...]예외가 올바르게 다시 렌더링되지만 표준 레일즈 복구 메커니즘에 의해 [sic] 캡처되지 않으며 표준 예외 페이지가 렌더링되지 않습니다.
언급URL : https://stackoverflow.com/questions/6813723/rescue-from-for-javascript-requests
반응형
'programing' 카테고리의 다른 글
| 상수 FILTER_SANITIZE_STRING이 더 이상 사용되지 않습니다. (0) | 2023.08.18 |
|---|---|
| 입력 필드에 텍스트 추가 (0) | 2023.08.18 |
| jQuery 데이터 테이블을 다시 로드/새로 고침하는 방법은 무엇입니까? (0) | 2023.08.18 |
| 자식 구성 요소의 Angular 4 호출 부모 메서드 (0) | 2023.08.18 |
| mysql에서 고유 키를 함께 변경합니다. (0) | 2023.08.18 |