如果路由不匹配,我正面临路由错误。如果路径不匹配,我想将页面重定向到404静态页面。 我用了一些参考,但它不工作。 没有路线匹配时,显示以下错误。 没有路由匹配[GET] “/ userss”如何在Ruby on Rails中处理路由错误
Rails.root:d:/红宝石/转让/库
如果路由不匹配,我正面临路由错误。如果路径不匹配,我想将页面重定向到404静态页面。 我用了一些参考,但它不工作。 没有路线匹配时,显示以下错误。 没有路由匹配[GET] “/ userss”如何在Ruby on Rails中处理路由错误
Rails.root:d:/红宝石/转让/库
在application_controller.rb
rescue_from ActionController::RoutingError, with: :render_404
private
def render_404
respond_to do |format|
format.html { render "#{Rails.root}/public/404.html", status: 404 }
format.json { render json: { status: 404, message: 'Page Not Found' } }
end
end
这不起作用,路由错误仍然存在 – aceBox
添加这些线在你的路由结束.RB文件写入
get '*path' => redirect('your path of static page')
你会得到它(无路由匹配....)在开发环境,但没有在生产环境中,如果你想呈现404尝试读取这个问题的http:// stackoverf low.com/questions/4156490/how-to-test-500-html-in-rails-development-env – itx