Class: UsersController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /users POST /users.json



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/r4/template/app/controllers/users_controller.rb', line 55

def create
  @user = User.new(user_params)

  respond_to do |format|
    if @user.save
      format.html { redirect_to users_url, notice: 'Uživatel byl uložen.' }
      format.json { render :show, status: :created, location: @user }
    else
      format.html { render :new }
      format.json { render json: @user.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

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



85
86
87
88
89
90
91
# File 'lib/r4/template/app/controllers/users_controller.rb', line 85

def destroy
  @user.destroy
  respond_to do |format|
    format.html { redirect_to users_url, notice: 'Uživatel byl odstraněn.' }
    format.json { head :no_content }
  end
end

#editObject

GET /users/1/edit



22
23
24
# File 'lib/r4/template/app/controllers/users_controller.rb', line 22

def edit

end

#edit_own_passwordObject



30
31
32
33
# File 'lib/r4/template/app/controllers/users_controller.rb', line 30

def edit_own_password
  @user = current_user
  render 'edit_password'
end

#edit_passwordObject



26
27
28
# File 'lib/r4/template/app/controllers/users_controller.rb', line 26

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

#indexObject

GET /users GET /users.json



7
8
9
# File 'lib/r4/template/app/controllers/users_controller.rb', line 7

def index
  @users = User.all
end

#newObject

GET /users/new



17
18
19
# File 'lib/r4/template/app/controllers/users_controller.rb', line 17

def new
  @user = User.new
end

#showObject

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



13
14
# File 'lib/r4/template/app/controllers/users_controller.rb', line 13

def show
end

#updateObject

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



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/r4/template/app/controllers/users_controller.rb', line 71

def update
  respond_to do |format|
    if @user.update(user_params)
      format.html { redirect_to users_url, notice: 'Uživatel byl upraven.' }
      format.json { render :show, status: :ok, location: @user }
    else
      format.html { render :edit }
      format.json { render json: @user.errors, status: :unprocessable_entity }
    end
  end
end

#update_passwordObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/r4/template/app/controllers/users_controller.rb', line 35

def update_password
  @user = User.find(params[:id])
  if @user.id == current_user.id
    if @user.update_with_password(user_params)
       @user, :bypass => true
      redirect_to root_path
    else
      render 'edit_password'
    end
  else
    if @user.update(user_params)
      redirect_to root_path
    else
      render 'edit_password'
    end
  end
end