Class: UsersController

Inherits:
ApplicationController show all
Defined in:
lib/generators/jwt_rails/templates/users_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#authorize_request, #is_owner, #is_owner_object, #not_found

Instance Method Details

#createObject

POST /users



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

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



39
40
41
# File 'lib/generators/jwt_rails/templates/users_controller.rb', line 39

def destroy
  @user.destroy
end

#indexObject

GET /users



9
10
11
12
# File 'lib/generators/jwt_rails/templates/users_controller.rb', line 9

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

#showObject

GET /users/username



15
16
17
# File 'lib/generators/jwt_rails/templates/users_controller.rb', line 15

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

#updateObject

PUT /users/username



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

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