Skip to content

Instantly share code, notes, and snippets.

@jsmestad
Created September 30, 2011 23:26
Show Gist options
  • Select an option

  • Save jsmestad/1255312 to your computer and use it in GitHub Desktop.

Select an option

Save jsmestad/1255312 to your computer and use it in GitHub Desktop.
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