Active Admin自定义400,500个错误页面

时间:2014-05-24 10:41:04

标签: ruby-on-rails activeadmin

如何在主动管理中实现自定义400和500错误页面?页面必须使用活动的管理布局。

1 个答案:

答案 0 :(得分:1)

进入您的路线:

match "/404", to: "errors#render_error"
match "/500", to: "errors#render_error"

构建名为ErrorsController

的新控制器
class ErrorsController < ApplicationController

  def render_error
    exception   = env["action_dispatch.exception"]
    status_code = ActionDispatch::ExceptionWrapper.new(env, exception).status_code

    @method, @message = if status_code == 404
      ["not_found", env["REQUEST_URI"]]
    else
      ["server_error", "#{exception.message}\n#{exception.backtrace.join('\n')}"]
    end

    render status: status_code
  end
end

然后在你的ApplicationController中:

private

  def not_found
    raise ActionController::RoutingError.new('Not Found')
  end

然后创建新视图以显示您想要的任何HTML。

希望它可以帮到你。

相关问题