Class: Testapi::ModelsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/testapi/models_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



9
10
11
12
# File 'app/controllers/testapi/models_controller.rb', line 9

def create
  @object = model.create!(attributes)
  render_object
end

#destroyObject



25
26
27
28
29
# File 'app/controllers/testapi/models_controller.rb', line 25

def destroy
  @object = model.find(params[:id])
  @object.destroy!
  render_object
end

#indexObject



4
5
6
7
# File 'app/controllers/testapi/models_controller.rb', line 4

def index
  @objects = model.all.reorder(:id)
  render_json @objects.map(&:attributes)
end

#showObject



14
15
16
17
# File 'app/controllers/testapi/models_controller.rb', line 14

def show
  @object = model.find(params[:id])
  render_object
end

#updateObject



19
20
21
22
23
# File 'app/controllers/testapi/models_controller.rb', line 19

def update
  @object = model.find(params[:id])
  @object.update!(attributes)
  render_object
end