Skip to content

@pmontrasio /post_params
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Gets the last POST parameters in Rails's log/development.log and pretty prints them
#!/bin/bash
# DO NOT USE ON PRODUCTION LOGS: maybe there are ways to inject Ruby code into the
# parameters hash and you'll end up evaluating it
#
# usage: post_params
# run this in the main Rails directory
# tested on Linux with ruby 1.9.3-p327, bash 4.2.24
last_post_line=`grep -n "Started POST " log/development.log |tail -1|cut -f1 -d":"`
hash_line=`expr $last_post_line + 2`
hash=`sed -n -e "${hash_line}p" log/development.log |sed -e 's/Parameters:/hash =/'`
echo "require 'pp';$hash;pp hash" | ruby -E UTF-8
@pmontrasio
Owner

A naive shell script to monitor the development log:

while true; do
  inotifywait -q log/development.log
  post_params
done

This is suboptimal because Rails modifies the log file many times during the processing of a request. The monitoring program should be smart enough to run post_params only when the file has been left alone for a few seconds.

@maca

It wasn't working for me with Rails 3.2.x

#!/bin/bash

echo $(grep -e "Started \(GET\|POST\|PUT\)" log/development.log | tail -1)
grep -e "Parameters:" log/development.log | tail -1 | sed "s|Parameters:\s||" | ruby -ne 'require "pp"; pp eval($_)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.