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
21 22 23 24 25 26 27 |
# File 'lib/active_record_api/rest/controller.rb', line 21 def create if model.save redirect_to_model else render json: model.errors, status: :unprocessable_entity end end |
#destroy ⇒ Object
37 38 39 40 |
# File 'lib/active_record_api/rest/controller.rb', line 37 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 19 |
# File 'lib/active_record_api/rest/controller.rb', line 16 def show return unless stale?(last_modified: model.updated_at) render json: model, serializer: serializer end |
#update ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/active_record_api/rest/controller.rb', line 29 def update if model.update(modifiable_params) redirect_to_model else render json: model.errors, status: :unprocessable_entity end end |