Class: ActiveRecordApi::Rest::Controller
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ActiveRecordApi::Rest::Controller
- Includes:
- GracefulErrors
- Defined in:
- lib/active_record_api/rest/controller.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#create ⇒ Object
:nocov:.
- #destroy ⇒ Object
- #index ⇒ Object
-
#new ⇒ Object
:nocov:.
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
:nocov:
27 28 29 30 31 32 33 |
# File 'lib/active_record_api/rest/controller.rb', line 27 def create if model.save render json: model, serializer: serializer else render json: model.errors, status: :unprocessable_entity end end |
#destroy ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/active_record_api/rest/controller.rb', line 43 def destroy if model.destroy render json: model else # :nocov: render json: model.errors, status: :unprocessable_entity # :nocov: end end |
#index ⇒ Object
10 11 12 13 14 |
# File 'lib/active_record_api/rest/controller.rb', line 10 def index response.headers['x-total'] = models_count response.headers['x-link-next'] = next_url unless next_url.nil? render json: models_full_results.limit(limit).offset(offset).order(id: :asc), each_serializer: serializer end |
#new ⇒ Object
:nocov:
21 22 23 24 |
# File 'lib/active_record_api/rest/controller.rb', line 21 def new action = request.query_parameters[:action] render json: .send(action, queryable_params.deep_symbolize_keys), serializer: serializer end |
#show ⇒ Object
16 17 18 |
# File 'lib/active_record_api/rest/controller.rb', line 16 def show render json: model, serializer: serializer end |
#update ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/active_record_api/rest/controller.rb', line 35 def update if model.update(modifiable_params) render json: model, serializer: serializer else render json: model.errors, status: :unprocessable_entity end end |