Created
September 30, 2011 23:26
-
-
Save jsmestad/1255312 to your computer and use it in GitHub Desktop.
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
| module MissingRecordHandler | |
| extend ActiveSupport::Concern | |
| included do | |
| rescue_from ActiveRecord::RecordNotFound, :with => :render_404 | |
| end | |
| module InstanceMethods | |
| def record_not_found | |
| raise ActiveRecord::RecordNotFound | |
| end | |
| private | |
| def render_404(exception=nil) | |
| logger.info "Rendering 404 with exception: #{exception.message}" if exception.present? | |
| respond_to do |format| | |
| format.html { render :file => "#{Rails.root}/public/404.html", :status => :not_found, :layout => false } | |
| format.json { render :text => 'Not Found', :status => :not_found } | |
| format.xml { head :not_found } | |
| format.any { head :not_found } | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment