// Javascript that submits data: function pushResults() { $.ajax({ type : "POST", url : "/mindfulness_tutor", beforeSend: function(jqXHR, settings) { jqXHR.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content')); }, dataType: "text/plain", data : "stats=" + serialize(resultsArray) + "&total=" + totalMeditationTime, }); } // Rails Controller code to save data: if request.post? current_user.meditation_sessions.create(data: params, raw_data: params.inspect) end // Database saves: data: --- !ruby/hash:ActiveSupport::HashWithIndifferentAccess raw_data: {"stats"=>"a:1:{i:0", "a:3:{i:0"=>nil, "i:62000"=>nil, "i:1"=>nil, "i:0"=>nil, "i:2"=>nil, "}}total"=>"120000", "action"=>"mindfulness_tutor", "controller"=>"pages"} // Post: stats=a:1:{i:0;a:3:{i:0;i:59000;i:1;i:0;i:2;i:0;}} // Rails log: Started POST "/mindfulness_tutor" for 127.0.0.1 at 2013-03-22 11:59:16 -0700 Processing by PagesController#mindfulness_tutor as */* Parameters: {"stats"=>"a:1:{i:0", "a:3:{i:0"=>nil, "i:59000"=>nil, "i:1"=>nil, "i:0"=>nil, "i:2"=>nil, "}}total"=>"60000"} User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 3 LIMIT 1 (0.1ms) begin transaction CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 3 LIMIT 1 SQL (60.9ms) INSERT INTO "meditation_sessions" ("created_at", "data", "raw_data", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?) [["created_at", Fri, 22 Mar 2013 11:59:16 PDT -07:00], ["data", {"stats"=>"a:1:{i:0", "a:3:{i:0"=>nil, "i:59000"=>nil, "i:1"=>nil, "i:0"=>nil, "i:2"=>nil, "}}total"=>"60000", "action"=>"mindfulness_tutor", "controller"=>"pages"}], ["raw_data", "{\"stats\"=>\"a:1:{i:0\", \"a:3:{i:0\"=>nil, \"i:59000\"=>nil, \"i:1\"=>nil, \"i:0\"=>nil, \"i:2\"=>nil, \"}}total\"=>\"60000\", \"action\"=>\"mindfulness_tutor\", \"controller\"=>\"pages\"}"], ["updated_at", Fri, 22 Mar 2013 11:59:16 PDT -07:00], ["user_id", 3]] (50.3ms) commit transaction Rendered pages/mindfulness_tutor.html.haml within layouts/application (0.3ms) Completed 200 OK in 181ms (Views: 64.9ms | ActiveRecord: 111.4ms) // request headers Accept:*/* Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3 Accept-Encoding:gzip,deflate,sdch Accept-Language:en-US,en;q=0.8 Connection:keep-alive Content-Length:61 Content-Type:application/x-www-form-urlencoded Cookie:_quiz_session=BAh7CkkiD3Nlc3Npb25faWQGOgZFRkkiJWU1Zjk1ZWMyNGQ4MGI0NTQ1MjNhNDNiNjE3Y2IwZWRiBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMWphT0RIUW4waXhMdURHUGFFU3luRFAxeFRJd1FwRmlXUUIxWk5HMlVWQTg9BjsARkkiGXdhcmRlbi51c2VyLnVzZXIua2V5BjsAVFsISSIJVXNlcgY7AEZbBmkISSIiJDJhJDEwJGZ5bTB4Z1ZPVll3SWNNRFdTOWoxRU8GOwBUSSIOcXVpel9kYXRlBjsARlU6IEFjdGl2ZVN1cHBvcnQ6OlRpbWVXaXRoWm9uZVsISXU6CVRpbWUN0UocwCvk0YYGOgtAX3pvbmVJIghVVEMGOwBUSSIfUGFjaWZpYyBUaW1lIChVUyAmIENhbmFkYSkGOwBGSXU7Bw3KShzAK%2BTRhgY7CEkiCFVUQwY7AFRJIghkYXkGOwBGSSIKdG9kYXkGOwBG--6d71d50955e9af265eda2ec23e9a99fe8b2c1410 Host:localhost:3000 Origin:http://localhost:3000 Referer:http://localhost:3000/mindfulness_tutor User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22 X-CSRF-Token:jaODHQn0ixLuDGPaESynDP1xTIwQpFiWQB1ZNG2UVA8= X-Requested-With:XMLHttpRequest