Class: Tramway::Api::V1::RecordsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/tramway/api/v1/records_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#render_error_with_text, #render_errors_for

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/tramway/api/v1/records_controller.rb', line 13

def create
  record_form = form_class.new model_class.new
  if record_form.submit params[:data][:attributes]
    render json: record_form.model,
      serializer: serializer_class,
      status: :created
  else
    render_errors_for record_form
  end
end

#indexObject



6
7
8
9
10
11
# File 'app/controllers/tramway/api/v1/records_controller.rb', line 6

def index
  records = model_class.active.order(id: :desc).send params[:scope] || :all
  render json: records,
    each_serializer: serializer_class,
    status: :ok
end

#updateObject



24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/tramway/api/v1/records_controller.rb', line 24

def update
  record_form = form_class.new model_class.find params[:id]
  if record_form.submit params[:data][:attributes]
    render json: record_form.model,
      serializer: serializer_class,
      status: :ok
  else
    render_errors_for record_form
  end
end