Skip to content

Instantly share code, notes, and snippets.

@cv
Created June 29, 2011 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cv/1054956 to your computer and use it in GitHub Desktop.
Save cv/1054956 to your computer and use it in GitHub Desktop.
a graceful degradation helper for dangerous operations in the template
module GracefulDegradationHelper
# doctest:
#
# >> gracefully { tag(:hello) }
# => "<hello />"
#
# >> gracefully { raise "oops" }
# => ""
#
def gracefully(&block)
begin
capture &block
rescue => e
Rails.logger.warn e # better exception handling goes here
""
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment