Class: Tramway::Api::V1::RecordsController
Instance Method Summary
collapse
#render_error_with_text, #render_errors_for
Instance Method Details
#create ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
|
# File 'app/controllers/tramway/api/v1/records_controller.rb', line 15
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,
include: '*',
status: :created
else
render_errors_for record_form
end
end
|
#destroy ⇒ Object
47
48
49
50
51
52
53
54
|
# File 'app/controllers/tramway/api/v1/records_controller.rb', line 47
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
|
# 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,
include: '*',
status: :ok
end
|
#show ⇒ Object
39
40
41
42
43
44
45
|
# File 'app/controllers/tramway/api/v1/records_controller.rb', line 39
def show
record = model_class.active.find params[:id]
render json: record,
serializer: serializer_class,
include: '*',
status: :ok
end
|
#update ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
|
# File 'app/controllers/tramway/api/v1/records_controller.rb', line 27
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,
include: '*',
status: :ok
else
render_errors_for record_form
end
end
|