Reputation: 3283
I got a task to pop up new window while clicking edit button.But i cannot get any solution for this. I have a class student and three attributes name,age and branch.I had created view through scaffolding.The task assigned to me is while clicking edit button,there should be a pop up window for edit those attributes.How can i do this? please help.I want to do this like jTable. This is my 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 %>
controller of this student class is
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 is
<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 is
match 'students/list' => 'students#list', :as => :list
Upvotes: 0
Views: 7101
Reputation: 6123
How about instead of using a pop-up you , you use a pop-up modal like the one included in Twitter Bootstrap? Rails doesn't handle pop-ups but you can generate them with javascript. There is also TopUp and prototype-window.
Upvotes: 2
Reputation: 245
There is no rails3 way of handling popups. You have to use a javascript library (jqueryui or other) and create a popup using that library. Rails will help you only in the way of generating HTML for that popup which you will pass to the library methods.
In another words, you will have a button which will send a request to the rails app. The rails app will generate javascript along with the popup html and send it back to the client for execution. The exact way of implementing this depends on which JS library you are using and you can do some research on this topic.
Upvotes: 1