Class: AsUser::UsersController

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

Instance Method Summary collapse

Methods included from SessionsHelper

#current_user, #current_user=, #current_user?, #redirect_back_or, #sign_in, #sign_out, #signed_in?, #store_location

Instance Method Details

#createObject

POST /users POST /users.json



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/as_user/users_controller.rb', line 42

def create
  @user = User.new(params[:user])
  
  respond_to do |format|
    if @user.save
       @user
      format.html { redirect_to @user, notice: 'User was successfully created.' }
      format.json { render json: @user, status: :created, location: @user }
    else
      flash[:error]="create user failed."
      format.html { render action: "new" }
      format.json { render json: @user.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /users/1 DELETE /users/1.json



82
83
84
85
86
87
88
89
90
# File 'app/controllers/as_user/users_controller.rb', line 82

def destroy
  #@user = User.find(params[:id])
  @user.destroy
  
  respond_to do |format|
    format.html { redirect_to users_url }
    format.json { head :no_content }
  end
end

#editObject

GET /users/1/edit



59
60
# File 'app/controllers/as_user/users_controller.rb', line 59

def edit
end

#edit_passwordObject



62
63
# File 'app/controllers/as_user/users_controller.rb', line 62

def edit_password
end

#indexObject

GET /users GET /users.json



9
10
11
12
13
14
15
16
# File 'app/controllers/as_user/users_controller.rb', line 9

def index
  @users = User.order("created_at desc").page([params[:page].to_i, 1].max).per(100)
  
  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @users }
  end
end

#newObject

GET /users/new GET /users/new.json



31
32
33
34
35
36
37
38
# File 'app/controllers/as_user/users_controller.rb', line 31

def new
  @user = User.new
  
  respond_to do |format|
    format.html # new.html.erb
    format.json { render json: @user }
  end
end

#showObject

GET /users/1 GET /users/1.json



20
21
22
23
24
25
26
27
# File 'app/controllers/as_user/users_controller.rb', line 20

def show
  @user = User.find(params[:id])
  
  respond_to do |format|
    format.html # show.html.erb
    format.json { render json: @user }
  end
end

#updateObject

PUT /users/1 PUT /users/1.json



67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/controllers/as_user/users_controller.rb', line 67

def update
  respond_to do |format|
    if @user.update_attributes(params[:user])
      format.html { redirect_to @user, notice: 'User was successfully updated.' }
      format.json { head :no_content }
    else
      flash[:error] = "update password failed."
      format.html { redirect_to @user }
      format.json { render json: @user.errors, status: :unprocessable_entity }
    end
  end
end