Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment