我通过DataTable显示数据并检测用户何时选择了一行。我想加载该行的编辑表单。
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,或者在表单标题中放置一个链接,则视图将呈现为OK。我在日志中可以看到的唯一区别是:
Processing by NeighboursController#edit as */*
通过浏览器直接加载或链接显示为:
Processing by NeighboursController#edit as HTML
由于控制器在任何一种情况下都能正确获取Id,我不确定是什么问题。如果id由JavaScript传递,为什么重要?顺便说一句,我已尝试使用不同的数据集,但具有相同的效果。
答案 0 :(得分:0)
编辑代码的控制器可能会显示问题,默认代码只返回HTML和JSon的数据,因此它可能不会为此调用返回任何内容。考虑始终通过删除大小写来返回HTML:
这是默认代码:
respond_to do |format|
format.html # new.html.haml
format.json { render json: @shop }
end
并通过调用render而不是this case语句来更改它以强制返回html。
BTW:*/*
代表:全部