How do I see the whole HTTP request in Rails

后端 未结 4 702
北海茫月
北海茫月 2020-12-29 04:20

I have a Rails application but after some time of development/debugging I realized that it would be very helpful to be able to see the whole HTTP request in the logfiles - l

4条回答
  •  孤城傲影
    2020-12-29 04:55

    You can rapidly see the request.env in a view via:

    • VIEW: <%= request.env.inspect %>

    If instead you want to log it in development log, from your controller:

    • CONTROLLER: Rails.logger.info(request.env)

    Here you can see a reference for the Request object.

    Rails automatically sets up logging to a file in the log/ directory using Logger from the Ruby Standard Library. The logfile will be named corresponding to your environment, e.g. log/development.log.

    To log a message from either a controller or a model, access the Rails logger instance with the logger method:

    class YourController < ActionController::Base
      def index
        logger.info request.env
      end
    end
    

    About the user, what are you using to authenticate It?

提交回复
热议问题