Sha256: 311ce05ac9efd5aeccbe9deb496f0ae4eec562ddbed0127beb9ae6d379024c35

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

module Api
  module V1
    class UsersController < BaseApiController
      authorize_resource
      respond_to :json

      def index
        respond_with(User.all)
      end

      def show
        @user = User.find(params[:id])
        respond_with(@user)
      end

      def create
        @user = User.new(user_params)

        if @user.save
          respond_with @user do |format|
            format.json { render json: @user, status: :created }
          end
        else
          respond_with_errors(@user)
        end
      end

      def update
        @user = User.find(params[:id])

        if @user.update_attributes(user_params)
          respond_with(@user)
        else
          respond_with_errors(@user)
        end
      end

      def destroy
        user = User.find(params[:id])

        if user.destroy
          render json: {}, status: 204
        else
          render json: {}, status: 500
        end
      end

      private

      def user_params
        params.require(:user).permit(:first_name, :last_name, :email,
                                     :password, :password_confirmation)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
voyage-1.44.0.14 lib/voyage/templates/api_users_controller.rb
voyage-1.44.0.13 lib/voyage/templates/api_users_controller.rb
voyage-1.44.0.11 lib/voyage/templates/api_users_controller.rb
voyage-1.44.0.12 lib/voyage/templates/api_users_controller.rb