General rescue throughout controller when id not found - RoR

后端 未结 4 1984
野的像风
野的像风 2021-02-07 11:21

I have stumbled upon a situation where my application looks for an id that does not exist in the database. An exception is thrown. Of course, this is a pretty standard situation

4条回答
  •  自闭症患者
    2021-02-07 11:55

    Rails has a built-in rescue_from class method:

    class CustomersController < ApplicationController
      rescue_from ActiveRecord::RecordNotFound, with: :index
      ...
    end
    

提交回复
热议问题