Sha256: 0bbfcd211a7188a5b35055aac287afe7066456712cb4ef3e6f54077f4d20c8cc

Contents?: true

Size: 691 Bytes

Versions: 40

Compression:

Stored size: 691 Bytes

Contents

module Api
  class UsersController < ActionController::API
    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

40 entries across 30 versions & 1 rubygems

Version Path
appmap-0.42.1 spec/fixtures/rails6_users_app/app/controllers/api/users_controller.rb
appmap-0.42.1 spec/fixtures/rails5_users_app/app/controllers/api/users_controller.rb
appmap-0.42.0 spec/fixtures/rails6_users_app/app/controllers/api/users_controller.rb
appmap-0.42.0 spec/fixtures/rails5_users_app/app/controllers/api/users_controller.rb
appmap-0.41.2 spec/fixtures/rails5_users_app/app/controllers/api/users_controller.rb
appmap-0.41.2 spec/fixtures/rails6_users_app/app/controllers/api/users_controller.rb
appmap-0.41.1 spec/fixtures/rails6_users_app/app/controllers/api/users_controller.rb
appmap-0.41.1 spec/fixtures/rails5_users_app/app/controllers/api/users_controller.rb
appmap-0.41.0 spec/fixtures/rails6_users_app/app/controllers/api/users_controller.rb
appmap-0.41.0 spec/fixtures/rails5_users_app/app/controllers/api/users_controller.rb
appmap-0.40.0 spec/fixtures/rails6_users_app/app/controllers/api/users_controller.rb
appmap-0.40.0 spec/fixtures/rails5_users_app/app/controllers/api/users_controller.rb
appmap-0.39.1 spec/fixtures/rails6_users_app/app/controllers/api/users_controller.rb
appmap-0.39.1 spec/fixtures/rails5_users_app/app/controllers/api/users_controller.rb
appmap-0.39.0 spec/fixtures/rails6_users_app/app/controllers/api/users_controller.rb
appmap-0.39.0 spec/fixtures/rails5_users_app/app/controllers/api/users_controller.rb
appmap-0.38.1 spec/fixtures/rails6_users_app/app/controllers/api/users_controller.rb
appmap-0.38.1 spec/fixtures/rails5_users_app/app/controllers/api/users_controller.rb
appmap-0.37.2 spec/fixtures/rails5_users_app/app/controllers/api/users_controller.rb
appmap-0.37.2 spec/fixtures/rails6_users_app/app/controllers/api/users_controller.rb