我有一个任务是在单击编辑按钮时弹出新窗口。但我无法得到任何解决方案。我有一个班级学生和三个属性名称,年龄和分支。我通过脚手架创建了视图。分配给我的任务是在单击编辑按钮时,应该有一个弹出窗口来编辑这些属性。我该怎么做?请帮助。我想像 jTable 那样做。这是我的 index.html.erb
<table class="tablelist">
<caption>Listing students</caption>
<tr>
<th>Name</th>
<th>Age</th>
<th>Branch</th>
<th></th>
<th></th>
</tr>
<% @students.each do |student| %>
<tr>
<td><%= student.name %></td>
<td><%= student.age %></td>
<td><%= student.branch %></td>
<td><%=link_to (image_tag("edit.png", :alt => 'Edit'), edit_student_path(student)) %></td>
<td><%= link_to 'Destroy', student, :method => :delete, :data => { :confirm => 'Are you sure?' } %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New Student', new_student_path %>
这个学生班的控制器是
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
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: 'StudentList',
actions: {
listAction: '/students/list',
createAction: '/students/newstudent',
updateAction: '/students/edit',
deleteAction: '/students/destroy'
},
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>
routes.rb 是
match 'students/list' => 'students#list', :as => :list