Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment