gpt4 book ai didi

ruby-on-rails - Rails 4 - 无法在生产中使用动态错误页面呈现 404(故障安全响应期间出错 : Missing template errors/show)

转载 作者:行者123 更新时间:2023-12-03 08:34:39 27 4
gpt4 key购买 nike

我按照此处的说明创建了动态错误页面: http://wearestac.com/blog/dynamic-error-pages-in-rails

当我通过/404 或/500 直接访问它们时,或者如果我尝试访问路由中未处理的 URL,它们会起作用。但是,当我尝试在 production 中使用 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。 (代码和跟踪都在下面)

在开发模式下,我得到了标准的 Rails 错误页面,这是意料之中的。

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

堆栈跟踪似乎不是很有帮助:

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'

最佳答案

尝试指定模板路径


def render_error(状态)
呈现状态:状态,模板:“错误/#{status}”
结尾

关于ruby-on-rails - Rails 4 - 无法在生产中使用动态错误页面呈现 404(故障安全响应期间出错 : Missing template errors/show),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25415465/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com