我得到一個任務,彈出新窗口,同時點擊編輯按鈕。但我無法得到任何解決方案。我有一個班學生和三個屬性名稱,年齡和分支。我通過腳手架創建了視圖。分配給我的任務是在單擊編輯按鈕時,應該有一個彈出窗口來編輯這些屬性。我該如何做?請help.I想要做這個像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
我想做這個像jtable.Any想法? – Niths
你需要投入自己的嘗試,並考慮將你的一些問題標記爲已回答。 – sunnyrjuneja
我想你已經看到了我的答案。 – Niths