Skip to content

Instantly share code, notes, and snippets.

@jugyo
Created January 18, 2011 04:04
Show Gist options
  • Save jugyo/783967 to your computer and use it in GitHub Desktop.
Save jugyo/783967 to your computer and use it in GitHub Desktop.
class MyFilter
def self.filter(controller)
insert_text controller, :before, /<\/body>/i, 'bar'
end
def self.insert_text(controller, position, pattern, new_text)
index = if match = controller.response.body.match(pattern)
match.offset(0)[position == :before ? 0 : 1]
else
controller.response.body.size
end
controller.response.body = controller.response.body.insert index, new_text
end
end
class ActionController::Base
after_filter MyFilter
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment