Class: UsersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/users_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#render_not_found_response

Instance Method Details

#createObject


15
16
17
18
19
20
21
22
# File 'app/controllers/users_controller.rb', line 15

def create
    user = User.new(user_params)
    if user.save
        render json: {status: "SUCCESS", message: "User saved", data: user}, status: :ok
    else
        render json: {status: "ERROR", message: "Saving failed", data: user.errors}, status: :unprocessable_entity
    end 
end

#destroyObject


30
31
32
33
34
# File 'app/controllers/users_controller.rb', line 30

def destroy
    user = User.find(params[:id])
    user.destroy
    render json: {status: "SUCCESS", message: "User deleted", data: user}, status: :ok        
end

#indexObject


5
6
7
8
# File 'app/controllers/users_controller.rb', line 5

def index
    users = User.all
    render json: {status: "SUCCESS", message: "All users currently in DB", data: users}, status: :ok
end

#showObject


10
11
12
13
# File 'app/controllers/users_controller.rb', line 10

def show
    user = User.find(params[:id])
    render json: {status: "SUCCESS", message: "User of requested Id", data: user}, status: :ok
end

#updateObject


24
25
26
27
28
# File 'app/controllers/users_controller.rb', line 24

def update
    user = User.find(params[:id])
    user.update_attributes(user_params)
    render json: {status: "SUCCESS", message: "User updated", data: user}, status: :ok              
end