Created
August 8, 2014 11:04
-
-
Save firedev/d0362e99925ba2e813d7 to your computer and use it in GitHub Desktop.
Redirects visitor up the restful route if record not found
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# controllers/concerns/record_not_found.rb | |
# | |
# Redirects visitor up the restful route if record not found | |
# | |
# /articles/404 -> /articles/ -> / | |
module RecordNotFound | |
extend ActiveSupport::Concern | |
included do | |
rescue_from ActiveRecord::RecordNotFound do |exception| | |
redirect_to Hash[:action, :index], alert: (admin? ? exception.message : t('errors.record_not_found')) | |
end | |
end | |
def routing_error | |
redirect_to "/#{params[:unmatched_route].split('/')[0..-2].join '/'}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment