While debugging an issue, its hard to trace a redirect_to in a rails application when you have a lot of gems and before_filters. So is there a way by which i can trace them faster? any methods or rails helpers available for that?
add the below method in your application controller
def redirect_to(options = {}, response_status = {})
::Rails.logger.error("Redirected by #{caller(1).first rescue "unknown"}")
super(options, response_status)
end
and then you will be able to see the file, method name that invoked the 'redirect_to' call in the log file (it will be logged)
eg:
Started GET "http://server.com/really_important_page" for 127.0.0.1
Processing by HomeController#really_important_page as HTML
Redirected by app/controllers/application_controller.rb:53:in `ensure_random_bugs'
Redirected to https://server.com/not_the_page_you_wanted
Completed 302 Found in 1ms
This saved my day so wanted to share here, hope you find it useful :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With