Ruby on Rails 找不到记录时的404

示例

从记录未找到救援错误,而不显示异常或白页:

class ApplicationController < ActionController::Base
  
  # ...你这里的其他东西 

  rescue_from ActiveRecord::RecordNotFound do |exception|
    redirect_to root_path, 404, alert: 'Record not found'
  end
end