Class: JSONAPI::ResourceController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- JSONAPI::ResourceController
- Includes:
- ResourceFor
- Defined in:
- lib/jsonapi/resource_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #create_association ⇒ Object
-
#create_operations_processor ⇒ Object
Override this to use another operations processor.
- #destroy ⇒ Object
- #destroy_association ⇒ Object
- #index ⇒ Object
- #show ⇒ Object
- #show_association ⇒ Object
- #update ⇒ Object
Methods included from ResourceFor
Instance Method Details
#create ⇒ Object
65 66 67 |
# File 'lib/jsonapi/resource_controller.rb', line 65 def create process_request_operations end |
#create_association ⇒ Object
69 70 71 |
# File 'lib/jsonapi/resource_controller.rb', line 69 def create_association process_request_operations end |
#create_operations_processor ⇒ Object
Override this to use another operations processor
86 87 88 |
# File 'lib/jsonapi/resource_controller.rb', line 86 def create_operations_processor JSONAPI::ActiveRecordOperationsProcessor.new end |
#destroy ⇒ Object
77 78 79 |
# File 'lib/jsonapi/resource_controller.rb', line 77 def destroy process_request_operations end |
#destroy_association ⇒ Object
81 82 83 |
# File 'lib/jsonapi/resource_controller.rb', line 81 def destroy_association process_request_operations end |
#index ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/jsonapi/resource_controller.rb', line 25 def index render json: JSONAPI::ResourceSerializer.new.serialize( resource_klass.find(resource_klass.verify_filters(@request.filters, context), context), @request.includes, @request.fields, context) rescue => e handle_exceptions(e) end |
#show ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/jsonapi/resource_controller.rb', line 35 def show keys = parse_key_array(params[resource_klass._key]) resources = [] keys.each do |key| resources.push(resource_klass.find_by_key(key, context)) end render json: JSONAPI::ResourceSerializer.new.serialize( resources, @request.includes, @request.fields, context) rescue => e handle_exceptions(e) end |
#show_association ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/jsonapi/resource_controller.rb', line 52 def show_association association_type = params[:association] parent_key = params[resource_klass._as_parent_key] parent_resource = resource_klass.find_by_key(parent_key, context) association = resource_klass._association(association_type) render json: { association_type => parent_resource.send(association.key)} rescue => e handle_exceptions(e) end |
#update ⇒ Object
73 74 75 |
# File 'lib/jsonapi/resource_controller.rb', line 73 def update process_request_operations end |