我的任务是在 rils 上用 ruby 做 jtable。这是我的控制器
def list
@students = Student.all
@jtable = {'Result' => 'OK','Records' => @students.map(&:attributes)}
respond_to do |format|
format.html # index.html.erb
format.json { render :json => @jtable}
end
end
def newstudent
@student = Student.new
@jtable = {'Result' => 'OK','Record' => @students.last(&:attributes)}
respond_to do |format|
format.html # new.html.erb
format.json { render :json => @jtable }
end
end
这是我的 index.html.erb 文件
<html>
<head>
<%=stylesheet_link_tag "jtable_blue","http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css",:media => "all" %>
<%= javascript_include_tag "jquery-1.8.3.min","http://code.jquery.com/ui/1.9.1/jquery-ui.js","jquery.jtable.min"%>
<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function () {
jQuery('#StudentTableContainer').jtable({
title: 'Table of people',
actions: {
listAction: '/students/list',
createAction: '/students/new',
updateAction: '/student/Update',
deleteAction: '/student/Delete'
},
fields: {
id: {
key: true,
create: false,
edit: false,
list: false
},
name: {
title: 'name',
width: '40%'
},
sex: {
title: 'sex',
width: '20%'
},
branch: {
title: 'branch',
width: '30%'
}
}
});
jQuery('#StudentTableContainer').jtable('load');
});
</script>
</head>
<body>
<div id="StudentTableContainer">
</div>
</body>
</html>
我收到类似“与服务器通信时发生错误”的错误。在添加新用户时。如何添加新学生?