Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 495
Michael Lee Avatar asked Mar 17 '18 19:03

Michael Lee


1 Answers

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"}
like image 86
Ana María Martínez Gómez Avatar answered Nov 15 '22 10:11

Ana María Martínez Gómez