CafeHey
CafeHey

Reputation: 5800

Best way to show custom messages for different Rails 500 messages?

I was wondering what the best way to display certain messages for different Rails 500 errors were.

How you set it up to access the error object on the 500 page?

For example if I could accsess the error NoMethodError to check what type it was on the 500 page, in the view I would like to show, this is just an example, show the message: "Error Code 1.", and then a different error code for different rails errors.

Upvotes: 0

Views: 219

Answers (1)

Mohsen Alizadeh
Mohsen Alizadeh

Reputation: 1603

use rescue_from in your base controller

class ApplicationController < ActionController::Base
  rescue_from NoMethodError do |exception|
    render plain: "Error Code 1.", status: 500
  end
end

Upvotes: 1

Related Questions