I need to monkey-patch one of the Rails core classes, specifically ActionView::Helpers::UrlHelper::ClassMethods.link_to
method. As far as I remember there are some events fired when parts of Rails are loaded, how to add handlers for them? Or should I just put the code into initializer?
Asked
Active
Viewed 1,653 times
2

synapse
- 5,588
- 6
- 35
- 65
-
1possible duplicate of [Monkey Patching in Rails 3](http://stackoverflow.com/questions/3420680/monkey-patching-in-rails-3) – marzapower Dec 09 '13 at 08:41
1 Answers
1
link_to
does not appear to be in ClassMethods. From here.
In config/initializers/url_helper_extensions.rb
module ActionView
module Helpers
module UrlHelper
alias_method :_link_to, :link_to
def link_to
# Your code ...
# Call original method if you want.
_link_to
end
end
end
end