Class: BaseApiController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
lib/baseapi/app/controllers/base_api_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /models/id.json

Parameters:

Returns:

  • String Json(Model)



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/baseapi/app/controllers/base_api_controller.rb', line 23

def create
  render 'model.json.jbuilder' if transaction(-> {
    self.send("before_#{__method__}") if self.methods.include?("before_#{__method__}".to_sym)
    params.each do |key, value|
      if key.present? and @Model.column_names.include?(key)
        @model.send("#{key}=", value)
      end
    end
    @model.save
    self.send("after_#{__method__}") if self.methods.include?("after_#{__method__}".to_sym)
  })
end

#destroyObject

DELETE /models/id.json

Parameters:

Returns:

  • String Json(Model)



55
56
57
58
59
60
61
# File 'lib/baseapi/app/controllers/base_api_controller.rb', line 55

def destroy
  render 'model.json.jbuilder' if transaction(-> {
    self.send("before_#{__method__}") if self.methods.include?("before_#{__method__}".to_sym)
    @model._destroy
    self.send("after_#{__method__}") if self.methods.include?("after_#{__method__}".to_sym)
  })
end

#indexObject

GET /models.json

Parameters:

  • Hash

Returns:

  • String Json(Models)



10
11
12
# File 'lib/baseapi/app/controllers/base_api_controller.rb', line 10

def index
  render 'models.json.jbuilder'
end

#showObject

GET /models/id.json

Returns:

  • String Json(Model)



16
17
18
# File 'lib/baseapi/app/controllers/base_api_controller.rb', line 16

def show
  render 'model.json.jbuilder'
end

#updateObject

PATCH/PUT /models/id.json

Parameters:

Returns:

  • String Json(Model)



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/baseapi/app/controllers/base_api_controller.rb', line 39

def update
  render 'model.json.jbuilder' if transaction(-> {
    self.send("before_#{__method__}") if self.methods.include?("before_#{__method__}".to_sym)
    params.each do |key, value|
      if key.present? and @Model.column_names.include?(key)
        @model.send("#{key}=", value)
      end
    end
    @model.save
    self.send("after_#{__method__}") if self.methods.include?("after_#{__method__}".to_sym)
  })
end