Permalink
Browse files

paginate users and delete user via ajax call

  • Loading branch information...
1 parent a4ae62c commit 75868923f66192d6cb5f86621ae4ec5f0d03dcea @daqing committed May 10, 2011
View
@@ -16,6 +16,7 @@ gem 'carrierwave'
gem 'rmmseg-cpp'
gem 'ferret'
gem 'capistrano'
+gem 'will_paginate'
# Use unicorn as the web server
# gem 'unicorn'
View
@@ -107,6 +107,7 @@ GEM
treetop (1.4.9)
polyglot (>= 0.3.1)
tzinfo (0.3.27)
+ will_paginate (3.0.pre)
workflow (0.8.0)
PLATFORMS
@@ -128,4 +129,5 @@ DEPENDENCIES
ruby-debug
sqlite3
thin
+ will_paginate
workflow
@@ -8,15 +8,19 @@ class Sudo::UsersController < ApplicationController
def index
- @users = User.all
+ @users = User.all.paginate(:page => params[:page])
end
def destroy
@user = User.find(params[:id])
- if @user.destroy
- redirect_to sudo_path, :success => success_do(:delete_user)
- else
- redirect_to sudo_path, :notice => failed(:delete_user)
+ respond_to do |format|
+ if @user.destroy
+ format.html { redirect_to sudo_path, :success => success_do(:delete_user) }
+ format.js
+ else
+ format.html { redirect_to sudo_path, :notice => failed(:delete_user) }
+ format.js { render :text => :error, :status => 500 }
+ end
end
end
@@ -1,7 +1,8 @@
-<tr>
+<tr id="user_<%= user.id %>">
+ <td class="quiet"><%= user.id %></td>
<td class="author"><%= link_to user.name, user %></td>
<td class="email"><%= user.email %></td>
<td><%= l(user.created_at, :format => :short) %></td>
<td><%= l(user.updated_at, :format => :short) %></td>
- <td><%= link_to t(:delete), user, :method => :delete, :confirm => t(:delete_confirm) %></td>
+ <td><%= link_to t(:delete), sudo_user_path(user), :method => :delete, :remote => true, :confirm => t(:delete_confirm) %></td>
</tr>
@@ -0,0 +1 @@
+$("#user_<%= @user.id %>").effect('highlight').fadeOut();
@@ -1,5 +1,6 @@
<table>
<tr>
+ <td width="20">ID</td>
<th width="80"><%= t(:username) %></th>
<th width="50">E-mail</th>
<th width="100"><%= t(:created_at) %></th>
@@ -8,3 +9,4 @@
</tr>
<%= render @users %>
</table>
+<%= will_paginate @users %>
View
@@ -0,0 +1,9 @@
+namespace :blumine do
+ desc "generate sample user data"
+ task :sample_users => :environment do
+ (1..30).each do |i|
+ name = "nama-#{i}"
+ User.create!(:name => name, :email => "#{name}@d.com", :password => name, :password_confirmation => name)
+ end
+ end
+end

0 comments on commit 7586892

Please sign in to comment.