Skip to content

Instantly share code, notes, and snippets.

@dux
Created March 28, 2013 11:00
Show Gist options
  • Save dux/5262359 to your computer and use it in GitHub Desktop.
Save dux/5262359 to your computer and use it in GitHub Desktop.
safe rails for replacement. on runtime error, reports error and object, does not brake the application
def sfor(list, &block)
for el in list
begin
yield(el)
rescue
concat(%[<div style="background-color:#fdd; padding:4px; border:1px solid #ccc;"><ul><li>Object: #{}#{el.as_link rescue '-'} (#{el.class.name})</li><li>Error: #{$!}</li></ul></div>])
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment