Class: API::V1::ContactFieldsController

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

Instance Method Summary collapse

Instance Method Details

#build_resourceObject



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

def build_resource
  @contact_field = ::ContactField.new(resource_params)
end

#createObject



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

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

#destroyObject



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

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

#indexObject

GET /api/v1/contact_fields



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

def index
  respond_with(@contact_fields)
end

#resource_paramsObject



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

def resource_params
  params.require(:contact_field).permit(:id, :name, :value_type, :validation_rules)
end

#showObject



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

def show
  respond_with(@contact_field)
end

#updateObject



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

def update
  

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