I'm currently using Jquery to serialize() a form, which contains a textarea, and POST it to Rails.
This works successfully in most cases, unless the textarea contains a line in quotes, on its own. If such a line exists Rails parses the contents between the quotes of that line as the params variable rather than the entire contents of the field.
For Example: take the task[description] of the following POST Request, sent to rails 2.3.8 via Jquery Post
FireBug: POST Parameters
authenticity_token r0uu4QQ9e73aEsSKl2LJRIWap1BSQWMKRaieCOwHEpg=
task[description] line1
"line2"
"line3"
line4
task[due_date]
task[project_id] 1
task[responsible_user_id] nobody
task[title] Parse Bug
Firebug: POST Source
authenticity_token=r0uu4QQ9e73aEsSKl2LJRIWap1BSQWMKRaieCOwHEpg%3D&
task%5Bproject_id%5D=1&task%5Bresponsible_user_id%5D=nobody&
task%5Bdue_date%5D=&task%5Btitle%5D=Parse+Bug&
task%5Bdescription%5D=line1%0A%22line2%22%0A%22line3%22%0Aline4
After rails parses the request params[:task][:description] gets the value of "line2" rather than the entire text block. (line1 "line2" "line3" line4)... see below
Rails development log
Processing TasksController#create (for 127.0.0.1 at 2010-07-26 17:05:06) [POST]
Parameters: {"action"=>"create", "authenticity_token"=>"r0uu4QQ9e73aEsSKl2LJRIWap1BSQWMKRaieCOwHEpg=",
"task"=>{"title"=>"Parse Bug", "project_id"=>"1", "due_date"=>"",
"description"=>"line2", "responsible_user_id"=>"nobody"}, "controller"=>"tasks"}
It seems that Rails parses from the POST source anything between two %0A%22 as the content of the variable rather than everything after the =
The quotes are escaped as %22 but should I be escaping them differently?
Much Thanks! If my description is confusing please ask me to clarify any part of it.
Updated
Here's the relative Jquery used:
$('#new-item').find('.submit').live('click', function(){
var form = $(this).closest('form');
$.post(form.attr("action"), form.serialize(), null, "script");
return false;
});
$.ajaxSetup({
'beforeSend':function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
})