Format Params in Rails Server Logs
Asked Answered
D

1

6

I have a webhooks controller, and i want to be able to view the params that get printed to my server logs in development in a nice readable format. Is awesome_print good for this? I'm trying to use prettyprint, example below, but the format is still not very readable.

Trying to use prettyprint to format params

  class DwollaWebhooksController < WebhooksController
  require 'pp'


    def create
      pp params

      case params[:topic]
        when 'customer_funding_source_verified'
          puts '----------customer_funding_source_verified-----------------'
      end

    end

Here's what that output looks like

<ActionController::Parameters {"id"=>"57dec892", "resourceId"=>"a0d172yx", "topic"=>"customer_bank_transfer_completed",...} permitted: false>

I'm looking for something that at least has proper indentation, multiple lines, etc

Downhill answered 17/3, 2018 at 19:16 Comment(0)
M
7

If you want to render the parameters in a "pretty" way, you can convert them to hash. Although as you have unpermitted params, you should use to_unsafe_h(), which gives you an unsafe, unfiltered ActiveSupport::HashWithIndifferentAccess representation of the parameters. So:

pp params.to_unsafe_h

which will output something like:

{"id"=>"57dec892",
 "resourceId"=>"a0d172yx",
 "topic"=>"customer_bank_transfer_completed"}
Mosa answered 17/3, 2018 at 22:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.