Class: AdminsController

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

Instance Attribute Summary

Attributes inherited from ApplicationController

#current_user

Instance Method Summary (collapse)

Instance Method Details

- (Object) create



17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/admins_controller.rb', line 17

def create
  if params.has_key?(:user_id)
    if User.exists?('id' => params[:user_id])
      @admin = Admin.create(user_id: params[:user_id], approved: true)
      render json: {created_admin: @admin}, status: 200
      return
    end
    render json: {error: 'user does not exist'}, status:  :bad_request
    return
  end
  render json: {error: 'user does not exist'}, status: :bad_request
end

- (Object) index



2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/admins_controller.rb', line 2

def index
  @admins = Admin.where('approved' => true)
            .includes(:user)

  @response_array = Array.new
  @admins.each do |a|
    @response_hash = {
      'data' => a,
      'user' => a.user
    }
    @response_array.push(@response_hash)
  end
  render json: @response_array.to_json, status: 200
end