Search code examples
ruby-on-railspretty-printawesomeprint

Format Params in Rails Server Logs


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


Solution

  • 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"}