Guest User

Untitled

a guest
May 21st, 2012
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. module MissingRecordHandler
  2. extend ActiveSupport::Concern
  3.  
  4. included do
  5. rescue_from ActiveRecord::RecordNotFound, :with => :render_404
  6. end
  7.  
  8. module InstanceMethods
  9. def record_not_found
  10. raise ActiveRecord::RecordNotFound
  11. end
  12.  
  13. private
  14.  
  15. def render_404(exception=nil)
  16. logger.info "Rendering 404 with exception: #{exception.message}" if exception.present?
  17.  
  18. respond_to do |format|
  19. format.html { render :file => "#{Rails.root}/public/404.html", :status => :not_found, :layout => false }
  20. format.json { render :text => 'Not Found', :status => :not_found }
  21. format.xml { head :not_found }
  22. format.any { head :not_found }
  23. end
  24. end
  25. end
  26. end
Advertisement
Add Comment
Please, Sign In to add comment