I am trying to override a the redirect_to method to add an additional param to the get requests (if thats present)
The redirect_to method is here
module ActionController
...................
module Redirecting
extend ActiveSupport::Concern
include AbstractController::Logger
...........................
def redirect_to(options = {}, response_status = {}) #:doc:
............................
self.status = _extract_redirect_to_status(options, response_status)
self.location = _compute_redirect_to_location(options)
self.response_body = "<html><body>You are being <a href=\"# {ERB::Util.h(location)}\">redirected</a>.</body></html>"
end
end
end
Here is how I am trying to override
module ActionController
module Redirecting
def redirect_to(options = {}, response_status = {})
if options
if options.is_a?(Hash)
options["custom_param"] = @custom_param
else
if options.include? "?"
options = options + "&custom_param=true"
else
options = options + "?custom_param=true"
end
end
end
super
end
end
end
I am apparently doing it wrong, and the super method call fails to work the way I wanted it. Hope someone could help.
I believe the problem here is that you are redefining the redirect_to method, not defining in a new place.
supercannot call the original because it no longer exists.The method you are looking for is
alias_method_chainThough, I think the more Rails friendly way would be to override
redirect_toin yourApplicationControllerThe benefits to this approach are that you aren’t patching rails and the application specific param is now set in your application controller.