-
-
Save moro/783979 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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