I would like to send a javascript array to be processed by a method in my controller. I think I am doing this way wrong. I am a total RoR, jquery, and ajax noobie. Here is what I have. Please give me some guidelines:
<div id="dataTable" class="dataTable" style="width: 680px;height: 300px; overflow: scroll"></div>
<button>Save!</button>
<script>
var first = true;
var totalChanges = new Array();
$("#dataTable").handsontable({
//...some code that generates appropriate array totalChanges
});
var data = //..some code
$("#dataTable").handsontable("loadData", data);
$(function() {
$( "button").button();
$( "button" ).click(function() {
alert("clicked");
$.ajax({
type: "POST",
url: "save",
data: JSON.stringify(totalChanges),
success: function() { alert("Success!"); }
});
});
});
</script>
I get this error:
POST http://10.10.136.244:6500/qtl_table/save 500 (Internal Server Error)
and
Started POST "/qtl_table/save" for 10.64.229.59 at Mon Jun 25 16:58:46 -0500 2012
Processing by QtlTableController#save as
Parameters: {"125,0,\"\",\"Ph upt 1-2\""=>{","=>{"125,1,\"\",\"DOR364\""=>{","=>{"125,2,\"\",\"G19833\""=>nil}}}}}
LOGGER WORKS
Completed 500 Internal Server Error in 81ms
ActionView::MissingTemplate (Missing template qtl_table/save with {:formats=>[:html], :handlers=>[:rjs, :rhtml, :erb, :rxml, :builder], :locale=>[:en, :en]} in view paths "/usr/home/benjamin/phavubase/qtl/app/views", "/usr/home/benjamin/phavubase/qtl/ruby/1.8/gems/declarative_authorization-0.5.5/app/views", "/usr/home/benjamin/phavubase/qtl/ruby/1.8/gems/devise_cas_authenticatable-1.1.1/app/views", "/usr/home/benjamin/phavubase/qtl/ruby/1.8/gems/devise-1.2.1/app/views", "/usr/home/benjamin/phavubase/qtl/ruby/1.8/gems/kaminari-0.12.4/app/views"):
app/controllers/qtl_table_controller.rb:18:in `data'
app/controllers/qtl_table_controller.rb:25:in `save'
Rendered ruby/1.8/gems/actionpack-3.0.8/lib/action_dispatch/middleware/templates/rescues/missing_template.erb within rescues/layout (0.8ms)
EDIT: app/controllers/qtl_table_controller.rb
...
def save
logger.debug "\nLOOK! WE SAVED! #{params[data]}\n"
render "index"
end
...
I added render :layout => false but I am still getting the missing template error. Also, someone suggested I just begin adding logic to my controller but the data parameter looks really funky. Its supposed to be an array of arrays that I turned into a string. Could you guys give me some more help?