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

#create ⇒ Object



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

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

#destroy ⇒ Object



43
44
45
46
47
48
49
# File 'app/controllers/tramway/api/v1/records_controller.rb', line 43

def destroy
  record = model_class.active.find params[:id]
  record.remove
  render json: record,
    serializer: serializer_class,
    status: :no_content
end

#index ⇒ Object



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

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

#show ⇒ Object



36
37
38
39
40
41
# File 'app/controllers/tramway/api/v1/records_controller.rb', line 36

def show
  record = model_class.active.find params[:id]
  render json: record,
    serializer: serializer_class,
    status: :ok
end

#update ⇒ Object



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

def update
  record_form = form_class.new model_class.active.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