【发布时间】:2014-05-05 15:52:38
【问题描述】:
我正在尝试在使用 cms gem 时处理 404 错误。在我过去的应用程序中,这种 404 方法似乎有效,但现在它无法挽救错误。有什么想法吗?
# application_controller.rb
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
rescue_from ActionController::RoutingError, :with => :render_404
def after_sign_in_path_for(resource)
admin_cms_path
end
private
def render_404(exception = nil)
if exception
logger.info "Rendering 404: #{exception.message}"
end
flash[:error] = 'The page you entered is unavailble, please send us an email if this is unexpected'
redirect_to root_path
end
end
路线
# routes.rb
Amskier::Application.routes.draw do
# ...
comfy_route :blog_admin, path: '/admin'
comfy_route :cms_admin, path: '/admin'
root to: "cms/content#show"
comfy_route :cms, path: '/', sitemap: false
end
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4 error-handling http-status-code-404