How do I redirect to 404 page when any records do not exist?

Viewed 869

eg. I have student and teacher model. if i visited the student or teacher profile that not exists in db it will raise as ActiveRecord::RecordNotFound.

I have tried this in the application controller but still got an error message ActiveRecord::RecordNotFound instead of 404 page.

class ApplicationController < ActionController::Base
  rescue_from ActiveRecord::RecordNotFound, with: :render_404
end

So, is there a solution for this?

Thanks.

2 Answers
Related