Class: API::V1::ContactTypesController

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

Instance Method Summary collapse

Instance Method Details

#build_resourceObject



44
45
46
# File 'app/controllers/api/v1/contact_types_controller.rb', line 44

def build_resource
  @contact_type = ContactType.new(resource_params)
end

#createObject



10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/api/v1/contact_types_controller.rb', line 10

def create

  if @contact_type.save
    respond_with(@contact_type)
  else
    respond_to do |format|
      format.json { render :json => {:fields => @contact_type.errors}, :status => :unprocessable_entity }
    end
  end
end

#destroyObject



37
38
39
40
41
42
# File 'app/controllers/api/v1/contact_types_controller.rb', line 37

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

#indexObject

GET /api/v1/contact_types



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

def index
  respond_with(@contact_types)
end

#resource_paramsObject



48
49
50
# File 'app/controllers/api/v1/contact_types_controller.rb', line 48

def resource_params
  params.require(:contact_type).permit(:id, :name)
end

#showObject



21
22
23
# File 'app/controllers/api/v1/contact_types_controller.rb', line 21

def show
  respond_with(@contact_type)
end

#updateObject



25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/api/v1/contact_types_controller.rb', line 25

def update


  if @contact_type.update(resource_params)
    respond_with(@contact_type)
  else
    respond_to do |format|
      format.json { render :json => {:fields => @contact_type.errors}, :status => :unprocessable_entity }
    end
  end
end