Class: UsersController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/generators/auth/templates/users_controller.rb

Overview

backend_authentication > app > controllers > users_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /users



19
20
21
22
23
24
25
26
27
# File 'lib/generators/auth/templates/users_controller.rb', line 19

def create
  @user = User.new(user_params)
  if @user.save
    render json: @user, status: :created
  else
    render json: { errors: @user.errors.full_messages },
           status: :unprocessable_entity
  end
end

#destroyObject

DELETE /users/username



38
39
40
# File 'lib/generators/auth/templates/users_controller.rb', line 38

def destroy
  @user.destroy
end

#indexObject

GET /users



8
9
10
11
# File 'lib/generators/auth/templates/users_controller.rb', line 8

def index
  @users = User.all
  render json: @users, status: :ok
end

#showObject

GET /users/username



14
15
16
# File 'lib/generators/auth/templates/users_controller.rb', line 14

def show
  render json: @user, status: :ok
end

#updateObject

PUT /users/username



30
31
32
33
34
35
# File 'lib/generators/auth/templates/users_controller.rb', line 30

def update
  unless @user.update(user_params)
    render json: { errors: @user.errors.full_messages },
           status: :unprocessable_entity
  end
end