Class: Grime::ApiController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/grime/api_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



37
38
39
40
# File 'app/controllers/grime/api_controller.rb', line 37

def create
  @object = scope.create!(object_params_for_create)
  render json: @object
end

#destroyObject



47
48
49
# File 'app/controllers/grime/api_controller.rb', line 47

def destroy
  render json: @object.destroy!
end

#indexObject



24
25
26
27
28
29
30
31
# File 'app/controllers/grime/api_controller.rb', line 24

def index
  if filter_params_present? && scope.respond_to?(:where)
    objects = scope.where(filter_params)
  else
    objects = scope.all
  end
  render json: objects
end

#showObject



33
34
35
# File 'app/controllers/grime/api_controller.rb', line 33

def show
  render json: @object
end

#updateObject



42
43
44
45
# File 'app/controllers/grime/api_controller.rb', line 42

def update
  @object.update!(object_params_for_update)
  render json: @object
end