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, #snake_case

Instance Method Details

#create ⇒ Object



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

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

#destroy ⇒ Object



48
49
50
51
52
53
54
55
# File 'app/controllers/tramway/api/v1/records_controller.rb', line 48

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

#index ⇒ Object



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

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

#show ⇒ Object



40
41
42
43
44
45
46
# File 'app/controllers/tramway/api/v1/records_controller.rb', line 40

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

#update ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/tramway/api/v1/records_controller.rb', line 28

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