看来我的Rails 5应用程序(仅在生产中 - 在Heroku上)导致application/not_found
缺少模板错误。此错误不会导致应用程序崩溃。
#<ActionView::MissingTemplate: Missing template application/not_found with {:locale=>[:en], :formats=>[nil], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :coffee, :haml, :jbuilder]}. Searched in:
* "/app/app/views"
* "/app/vendor/bundle/ruby/2.3.0/gems/devise-authy-1.8.1/app/views"
* "/app/vendor/bundle/ruby/2.3.0/gems/devise_invitable-1.7.2/app/views"
* "/app/vendor/bundle/ruby/2.3.0/bundler/gems/devise-71fc5b351a8e/app/views"
* "/app/vendor/bundle/ruby/2.3.0/gems/kaminari-core-1.0.1/app/views"
>
我将*path
发送到application#not_found
以捕获拼写错误的请求。
在ApplicationController
:
rescue_from (ActiveRecord::RecordNotFound) { |exception| handle_exception(exception, 404) }
rescue_from (AbstractController::ActionNotFound) { |exception| handle_exception(exception, 404) }
rescue_from (ActionController::RoutingError) { |exception| handle_exception(exception, 404) }
def not_found
raise ActionController::RoutingError.new(params[:path] || 'Not Found')
end
protected
def handle_exception ex, status
render_error ex, status
logger.error ex
end
def render_error ex, status
@status_code = status
respond_to do |format|
if status == 404
format.html { render template: 'errors/not_found', status: status }
end
format.all { render nothing: true, status: status }
end
end
我认为通过指定render template: 'errors/not_found'
Rails并且知道模板已经渲染。