내 컨트롤러의 메소드로 처리 할 자바 스크립트 배열을 보내고 싶습니다. 내가 잘못하고 있다고 생각합니다. 저는 총 RoR, jquery 및 ajax noobie입니다. 여기에 내가 가진 것이있다. 나에게 몇 가지 지침을 제공하십시오 :Ruby on Rails : Ruby 컨트롤러에 자바 스크립트 데이터 보내기
<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>
를 내가 얻을이 오류 :
POST http://10.10.136.244:6500/qtl_table/save 500 (Internal Server Error)
및
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)
편집 : 응용 프로그램을/컨트롤러/qtl_table_controller.rb
...
def save
logger.debug "\nLOOK! WE SAVED! #{params[data]}\n"
render "index"
end
...
나는 rende를 추가했다. r : layout => false 그러나 여전히 누락 된 템플릿 오류가 발생합니다. 또한, 누군가 내 컨트롤러에 논리를 추가하기 시작했으나 데이터 매개 변수는 정말 펑키하게 보일 것을 제안했습니다. 배열로 배열 된 문자열로 바뀌 었습니다. 얘들 아 좀 도와 줄래?
당신이 당신의 컨트롤러 코드를 게시 할 수에
을 추가하여 아무것도 렌더링하지 레일을 알 수 있습니까? 저장하고 템플릿을 렌더링하려는 것일 수도 있습니다. – agmcleod
지금 컨트롤러에 논리가 없습니다. – bdeonovic