transaction log goodness

even in production mode, a rails app will save the contents of every get and post made. this saved my bacon today as a questionare form had two fields specified incorrectly such that their values were not being saved to the database. by parsing the log/production.log file, the data was recovered.

$ script/runner -e production 'Demographic.restore_from_log' (truncated version) class Demographic < ActiveRecord::Base   def self.restore_from_log     IO.foreach("log/production.log") do |l|       form_log = /Parameters: (.*)/.match(l)       if form_log         params = eval(form_log[1])        # the params hash contains the variables from the post     end   end end

tags: