捕获 ActiveRecord::RecordNotFound 输出 404 页面

class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception

  rescue_from ActiveRecord::RecordNotFound, with: :render_404

  protected
  def render_404
    render(file: "#{Rails.root}/public/404.html", :layout => false, :status => 404)
  end
end
This entry was posted in ruby on rails and tagged , , . Bookmark the permalink.

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>