Skip to content

Instantly share code, notes, and snippets.

@moro
Forked from jugyo/gist:783967
Created January 18, 2011 04:14
Show Gist options
  • Save moro/783979 to your computer and use it in GitHub Desktop.
Save moro/783979 to your computer and use it in GitHub Desktop.
class MyFilter
class << self
def method_missing(m_name, *ignore)
new(m_name)
end
end
def initialize(bar)
@bar = bar
end
def filter(controller)
insert_text controller, :before, /<\/body>/i, @bar
end
private
def 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.bar
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment