in your application.rb
ActionController::Base
rescue_from ActionController::RoutingError, :with => :render_404
private
def render_404(exception = nil)
if exception
logger.info "Rendering 404: #{exception.message}"
end
render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
end
本文介绍了一种在Ruby on Rails应用中处理路由错误并返回定制化的404页面的方法。通过定义rescue_from方法捕获ActionController::RoutingError异常,并使用专用的404页面进行渲染,可以改善用户体验。
6

被折叠的 条评论
为什么被折叠?



