Class: UsersController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#appendObject



21
22
# File 'app/controllers/users_controller.rb', line 21

def append
end

#createObject



23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/users_controller.rb', line 23

def create
  @user=User.new(params[:user])
  @user.last_lip=lip
  #redirect_to @user.save ? users_path : new_user_path
  if @user.save
    redirect_to users_path
  else
    redirect_to new_user_path
  end
end

#destroyObject



54
55
56
57
58
59
60
61
# File 'app/controllers/users_controller.rb', line 54

def destroy
  begin
    @user.destroy
  rescue
    flash[:error]="删除失败!"
  end
  redirect_to users_path
end

#editObject



33
34
# File 'app/controllers/users_controller.rb', line 33

def edit
end

#finduserObject



9
10
11
# File 'app/controllers/users_controller.rb', line 9

def finduser
  @user=User.find(params[:id])
end

#indexObject



13
14
15
16
17
# File 'app/controllers/users_controller.rb', line 13

def index
  @page,@per_page=params[:page],5
  @minum = @page ? @per_page*(@page.to_i-1) : 0
  @users=User.paginate :page=>@page,:per_page=>@per_page,:order=>"created_at DESC"
end

#lipObject



6
7
8
# File 'app/controllers/users_controller.rb', line 6

def lip
  request.remote_ip
end

#newObject



18
19
20
# File 'app/controllers/users_controller.rb', line 18

def new
  @user=User.new
end

#searchObject



36
37
38
39
40
41
42
43
# File 'app/controllers/users_controller.rb', line 36

def search
  redirect_to users_path and return if params[:str].blank?
  str=params[:str].strip
  @users = ["!",">","<"].include?(str[0]) ? User.search_ltime(str) : User.search(str)
  @page,@per_page=params[:page],5
  @minum = @page ? @per_page*(@page.to_i-1) : 0
  @users=@users.paginate :page=>@page,:per_page=>@per_page,:order=>"created_at DESC"
end

#showObject



52
53
# File 'app/controllers/users_controller.rb', line 52

def show
end

#updateObject



45
46
47
48
49
50
51
# File 'app/controllers/users_controller.rb', line 45

def update
  params[:user][:last_ip]=lip
  lpassword=params[:user][:lpassword]
  params[:user][:lpassword] = lpassword.blank? ? @user.lpassword : User.encrypt(lpassword)
  @user.update_attributes(params[:user])
  redirect_to users_path
end