DataTable을 통해 데이터를 표시하고 사용자가 행을 선택하면 검색합니다. 그 행에 대한 편집 양식을로드하고 싶습니다.Rails 3.2.1 브라우저에 형식이 표시되지 않습니다.
var oTable;
$(document).ready(function() {
/* Init the table */
TableTools.DEFAULTS.aButtons = [];
oTable = $("#neighbours").dataTable({
sPaginationType: "full_numbers",
bJQueryUI: true,
"bProcessing": true,
"bServerSide": true,
iDisplayLength: 25,
sAjaxSource: $('#neighbours').data('source'),
"aoColumns": [
null,
null,
null,
null,
null
],
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sRowSelect": "single",
"fnRowSelected": function (node) {
var oTT = TableTools.fnGetInstance('neighbours');
var aData = oTT.fnGetSelectedData();
// alert (aData[0][4]);
n = aData[0][4];
$.get('edit/' + n);
}
},
});
내 관련 컨트롤러 코드 :
def edit
logger.debug "Edit in Controller for Neighbour ID #{params[:id]}"
@neighbour = Neighbour.find(params[:id])
@localities = Locality.find(:all)
@highways = Highway.find(:all)
end
내가 올바른 ID가 컨트롤러에 전달하고 WebBrick 뷰이 추출물 쇼로 렌더링 된 것을보고하는 로그에서 볼 수 있습니다.
Started GET "/neighbours/edit/39" for 127.0.0.1 at 2012-08-08 18:10:20 +1000
Processing by NeighboursController#edit as */*
Parameters: {"id"=>"39"}
Edit in Controller for Neighbour ID 39
Rendered neighbours/_form.html.erb (4341.0ms)
Rendered neighbours/edit.html.erb within layouts/neighbours (4410.0ms)
Completed 200 OK in 5564ms (Views: 4479.6ms | ActiveRecord: 28.0ms)
보기가 브라우저에 표시되지 않습니다. 그러나 브라우저 주소 표시 줄에 localhost : 3000/neighbors/edit/39를 입력하거나 양식 헤더에 링크를 배치하면보기가 정상적으로 렌더링됩니다. 내가 로그에서 볼 수있는 유일한 차이점은 라인 : 브라우저 또는 보여줍니다 링크를 통해 직접 부하로
Processing by NeighboursController#edit as */*
등 :
Processing by NeighboursController#edit as HTML
컨트롤러가 그냥 올바르게 ID를 가져옵니다 때문에 어느 경우 든 나는 틀린 것이 확실하지 않다. id가 JavaScript에 의해 전달되면 왜 중요합니까? 그건 그렇고, 나는 다른 데이터 세트로 동일한 시도를했지만 동일한 효과를 보았습니다.
감사합니다. Hugo. 내가 제공 한 기본 코드가 레일즈가 백그라운드에서 수행하고있는 것으로 가정합니다 - 맞습니까? render (draw html : @neighbour)하지만 동일한 결과를 지정하여이를 오버라이드하려고했습니다. 또한 자바 스크립트의이 요청이 링크를 클릭하여 컨트롤러 호출과 다른 이유를 알고 싶습니다. 감사. – need2surf