Sha256: 5f50680832d477a227f8834d7f2c9c9a98372b7e8db165642b5274e211ff9424

Contents?: true

Size: 691 Bytes

Versions: 23

Compression:

Stored size: 691 Bytes

Contents

module Api
  class UsersController < ApplicationController
    def index
      @users = User.all
      render json: @users
    end

    def create
      @user = build_user(params.slice(:login).to_unsafe_h)
      unless @user.valid?
        error = {
          code: 'invalid',
          target: 'User',
          message: @user.errors.full_messages.join(', '),
          details: @user.errors.map { |k, v| { code: 'invalid', target: k, message: Array(v).join(', ') } }
        }
        return render json: error, status: :unprocessable_entity
      end
      @user.save
      render json: @user, status: :created
    end

    def build_user(params)
      User.new(params)
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
appmap-0.39.0 spec/fixtures/rails4_users_app/app/controllers/api/users_controller.rb
appmap-0.38.1 spec/fixtures/rails4_users_app/app/controllers/api/users_controller.rb
appmap-0.37.2 spec/fixtures/rails4_users_app/app/controllers/api/users_controller.rb
appmap-0.37.0 spec/fixtures/rails4_users_app/app/controllers/api/users_controller.rb
appmap-0.36.0 spec/fixtures/rails4_users_app/app/controllers/api/users_controller.rb
appmap-0.35.2 spec/fixtures/rails4_users_app/app/controllers/api/users_controller.rb
appmap-0.35.1 spec/fixtures/rails4_users_app/app/controllers/api/users_controller.rb
appmap-0.35.0 spec/fixtures/rails4_users_app/app/controllers/api/users_controller.rb
appmap-0.34.5 spec/fixtures/rails4_users_app/app/controllers/api/users_controller.rb
appmap-0.34.4 spec/fixtures/rails4_users_app/app/controllers/api/users_controller.rb
appmap-0.34.2 spec/fixtures/rails4_users_app/app/controllers/api/users_controller.rb
appmap-0.34.1 spec/fixtures/rails4_users_app/app/controllers/api/users_controller.rb
appmap-0.34.0 spec/fixtures/rails4_users_app/app/controllers/api/users_controller.rb
appmap-0.33.0 spec/fixtures/rails4_users_app/app/controllers/api/users_controller.rb
appmap-0.32.0 spec/fixtures/rails4_users_app/app/controllers/api/users_controller.rb
appmap-0.31.0 spec/fixtures/rails4_users_app/app/controllers/api/users_controller.rb
appmap-0.28.1 spec/fixtures/rails4_users_app/app/controllers/api/users_controller.rb
appmap-0.28.0 spec/fixtures/rails4_users_app/app/controllers/api/users_controller.rb
appmap-0.27.0 spec/fixtures/rails4_users_app/app/controllers/api/users_controller.rb
appmap-0.26.1 spec/fixtures/rails4_users_app/app/controllers/api/users_controller.rb