class UsersController

Public Instance Methods

create() click to toggle source

POST /users

# 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
destroy() click to toggle source

DELETE /users/{username}

# File lib/generators/jwt_rails/templates/users_controller.rb, line 39
def destroy
  @user.destroy
end
index() click to toggle source

GET /users

# File lib/generators/jwt_rails/templates/users_controller.rb, line 9
def index
  @users = User.all
  render json: @users, status: :ok
end
show() click to toggle source

GET /users/{username}

# File lib/generators/jwt_rails/templates/users_controller.rb, line 15
def show
  render json: @user, status: :ok
end
update() click to toggle source

PUT /users/{username}

# 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

Private Instance Methods

find_user() click to toggle source
# File lib/generators/jwt_rails/templates/users_controller.rb, line 45
def find_user
  @user = User.find_by_username!(params[:_username])
rescue ActiveRecord::RecordNotFound
  render json: { errors: 'User not found' }, status: :not_found
end
user_params() click to toggle source
# File lib/generators/jwt_rails/templates/users_controller.rb, line 51
def user_params
  params.require(:user).permit(:name, :username, :email, :password, :password_confirmation)
end