Class: API::V1::ContactsController

Inherits:
Faalis::APIController
  • Object
show all
Defined in:
app/controllers/api/v1/contacts_controller.rb

Instance Method Summary collapse

Instance Method Details

#build_resourceObject



29
30
31
# File 'app/controllers/api/v1/contacts_controller.rb', line 29

def build_resource
  @contact = ::Contact.new(resource_params)
end

#createObject



10
11
12
# File 'app/controllers/api/v1/contacts_controller.rb', line 10

def create
  create_or_update(:create)
end

#destroyObject



22
23
24
25
26
27
# File 'app/controllers/api/v1/contacts_controller.rb', line 22

def destroy
  ids = params[:id].split(",")
  @contacts = ::Contact.where(:id => ids)
  authorize! :destroy, @contacts
  @contacts.destroy_all
end

#indexObject

GET /api/v1/contacts



6
7
8
# File 'app/controllers/api/v1/contacts_controller.rb', line 6

def index
  respond_with(@contacts)
end

#resource_paramsObject



33
34
35
# File 'app/controllers/api/v1/contacts_controller.rb', line 33

def resource_params
  params.require(:contact).permit(:id, :prefix, :first_name, :middle_name, :last_name, :suffix, :organization, :is_organization)
end

#showObject



14
15
16
# File 'app/controllers/api/v1/contacts_controller.rb', line 14

def show
  respond_with(@contact)
end

#updateObject



18
19
20
# File 'app/controllers/api/v1/contacts_controller.rb', line 18

def update
  create_or_update(:update)
end