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
Instance Method Details
#create ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/active_record_api/rest/controller.rb', line 20 def create if model.save render json: model else render json: model.errors, status: :unprocessable_entity end end |
#destroy ⇒ Object
36 37 38 39 |
# File 'lib/active_record_api/rest/controller.rb', line 36 def destroy model.destroy! head :no_content 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 render json: models, each_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
28 29 30 31 32 33 34 |
# File 'lib/active_record_api/rest/controller.rb', line 28 def update if model.update(modifiable_params) render json: model else render json: model.errors, status: :unprocessable_entity end end |