Rails 4-동적 오류 페이지가있는 프로덕션에서 404를 렌더링 할 수 없음 (안전한 응답 중 오류 : 템플릿 오류 / 표시 누락)

제레미 길릭

다음 지침에 따라 동적 오류 페이지를 만들었습니다. http://wearestac.com/blog/dynamic-error-pages-in-rails

/ 404 또는 / 500을 통해 직접 이동하거나 경로에서 처리되지 않는 URL로 이동하려고 할 때 작동합니다. 그러나 프로덕션render :status => 404 에서 작업에서 404를 강제로 시도 하면 다음 오류가 발생합니다.

Error during failsafe response: Missing template errors/show, application/show with {:locale=>[:en, :"en-US"], :formats=>[:html, :text, :js, :css, :ics, :csv, :vcf, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby]}. 
Searched in:
  * "/Users/Jeremy/Projects/git/rails/app/views"

404 오류 페이지는 views / errors / 404.html.erb에 있습니다. 스택 추적에서 Rails가 ErrorsController에 액세스하는 것처럼 보이지도 않습니다. (코드와 트레이스 모두 아래에 있습니다)

In development mode I get the standard rails error page, which is to be expected.

application.rb

...
config.exceptions_app = self.routes
...

routes.rb

...

# Error pages
%w( 404 500 ).each do |code|
  get code, :to => "errors#show", :code => code
end

...

errors_controller.rb

class ErrorsController < ApplicationController
  def show
    render status_code.to_s, :status => status_code
  end
protected
  def status_code
    params[:code] || 500
  end
end

The stack trace doesn't seem very helpeful:

Error during failsafe response: Missing template errors/show, application/show with {:locale=>[:en, :"en-US"], :formats=>[:html, :text, :js, :css, :ics, :csv, :vcf, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby]}. Searched in:
  * "/Users/Jeremy/Projects/git/rails/app/views"

  /Users/Jeremy/.rvm/gems/ruby-2.1.0/gems/actionview-4.1.1/lib/action_view/path_set.rb:46:in `find'
  /Users/Jeremy/.rvm/gems/ruby-2.1.0/gems/actionview-4.1.1/lib/action_view/lookup_context.rb:124:in `find'
  /Users/Jeremy/.rvm/gems/ruby-2.1.0/gems/actionview-4.1.1/lib/action_view/renderer/abstract_renderer.rb:18:in `find_template'
  /Users/Jeremy/.rvm/gems/ruby-2.1.0/gems/actionview-4.1.1/lib/action_view/renderer/template_renderer.rb:41:in `determine_template'
  /Users/Jeremy/.rvm/gems/ruby-2.1.0/gems/actionview-4.1.1/lib/action_view/renderer/template_renderer.rb:8:in `render'
  /Users/Jeremy/.rvm/gems/ruby-2.1.0/gems/actionview-4.1.1/lib/action_view/renderer/renderer.rb:42:in `render_template'
  /Users/Jeremy/.rvm/gems/ruby-2.1.0/gems/actionview-4.1.1/lib/action_view/renderer/renderer.rb:23:in `render'
  /Users/Jeremy/.rvm/gems/ruby-2.1.0/gems/actionview-4.1.1/lib/action_view/rendering.rb:99:in `_render_template'
  /Users/Jeremy/.rvm/gems/ruby-2.1.0/gems/actionpack-4.1.1/lib/action_controller/metal/streaming.rb:217:in `_render_template'
  /Users/Jeremy/.rvm/gems/ruby-2.1.0/gems/actionview-4.1.1/lib/action_view/rendering.rb:82:in `render_to_body'
  /Users/Jeremy/.rvm/gems/ruby-2.1.0/gems/actionpack-4.1.1/lib/action_controller/metal/rendering.rb:32:in `render_to_body'
  /Users/Jeremy/.rvm/gems/ruby-2.1.0/gems/actionpack-4.1.1/lib/action_controller/metal/renderers.rb:32:in `render_to_body'
  /Users/Jeremy/.rvm/gems/ruby-2.1.0/gems/actionpack-4.1.1/lib/abstract_controller/rendering.rb:25:in `render'
  /Users/Jeremy/.rvm/gems/ruby-2.1.0/gems/actionpack-4.1.1/lib/action_controller/metal/rendering.rb:16:in `render'
  /Users/Jeremy/.rvm/gems/ruby-2.1.0/gems/actionpack-4.1.1/lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render'
  /Users/Jeremy/.rvm/gems/ruby-2.1.0/gems/activesupport-4.1.1/lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
  /Users/Jeremy/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/benchmark.rb:294:in `realtime'
  /Users/Jeremy/.rvm/gems/ruby-2.1.0/gems/activesupport-4.1.1/lib/active_support/core_ext/benchmark.rb:12:in `ms'
  /Users/Jeremy/.rvm/gems/ruby-2.1.0/gems/actionpack-4.1.1/lib/action_controller/metal/instrumentation.rb:41:in `block in render'
  /Users/Jeremy/.rvm/gems/ruby-2.1.0/gems/actionpack-4.1.1/lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
  /Users/Jeremy/.rvm/gems/ruby-2.1.0/gems/actionpack-4.1.1/lib/action_controller/metal/instrumentation.rb:40:in `render'
  /Users/Jeremy/Projects/git/rails/app/controllers/application_controller.rb:86:in `render_not_found'
  /Users/Jeremy/Projects/git/rails/app/controllers/application_controller.rb:39:in `set_catalog_type'
mestachs

Try specifying a template path

def render_error(status) render status: status, template: "errors/#{status}" end

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관