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.
try this :)
class ApplicationController < ActionController::Base
rescue_from ActiveRecord::RecordNotFound, with: :record_not_found
private
def record_not_found
render file: "#{Rails.root}/public/404", layout: true, status: :not_found
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With