class ActionController::Base
Public Class Methods
monkeypatch_mvcoffee()
click to toggle source
Call this class macro in your application_controller.rb file if you want to do the monkeypatch for the whole application.
I could make it so this happens by default, but I think it should require an explicit action on the programmer's part to make a monkeypatch with potentially unintended consequences happen. This is in keeping with the principle of Least Surprise. If something goes wonky after you called this method, well, you know you called it, so you can comment it out (and probably curse me online) Let's hope it never comes to that.…
# File lib/mvcoffee-rails.rb, line 30 def self.monkeypatch_mvcoffee # The really cool thing about monkeypatching this method is that it gets called # automagically in your controllers at the end of each action if the action falls # through. So, with this in place, with no extra action required by the # programmer, the MVCoffee thing will just happen. This means you can do a # redirect even on a json request without even thinking about it! define_method :render do |action = nil, opts = {}| # Uncomment this is you want to prove it to yourself that it really is doing # the around alias. # puts "!!!! Doing monkeypatched render !!!!!" render_mvcoffee action, opts end # And the cool thing about monkeypatching this method is that you can call it # indiscriminately without doing that format...do business checking for json # and avoiding redirecting if it is json. Just go ahead and call redirect_to, # and the client framework will do the right thing, handling the redirect AFTER # processing the json fetched over ajax. define_method :redirect_to do |action, opts = {}| # Uncomment this is you want to prove it to yourself that it really is doing # the around alias. # puts "!!!! Doing monkeypatched redirect_to !!!!!" @mvcoffee.set_redirect action, opts render_mvcoffee end end