Class: JSONAPI::RelationshipsController

Instance Method Summary collapse

Methods included from ResourceActions

#build_resource_for_create, #create, #handle_create_exception, #index

Methods included from JSONAPI::ResourceActions::TypeValidation

#validate_resource_id!, #validate_resource_type!

Methods included from JSONAPI::ResourceActions::Serialization

#serialize_collection, #serialize_resource

Methods included from JSONAPI::ResourceActions::Preloading

#preload_includes

Methods included from JSONAPI::ResourceActions::FieldValidation

#validate_fields_param, #validate_include_param, #validate_sort_param

Methods included from JSONAPI::ResourceActions::FilterValidation

#validate_filter_param

Methods included from ActiveStorageSupport

#active_storage_attachment?, #append_only_enabled?, #attach_active_storage_files, #extract_active_storage_params_from_hash, #filter_active_storage_from_includes, #filter_polymorphic_from_includes, #find_blob_by_signed_id, #process_active_storage_attachment, #purge_on_nil_enabled?, #resolve_model_class_for_attachment, #serialize_active_storage_relationship, #serialize_blob_identifier

Methods included from ControllerHelpers::Authorization

#current_user

Instance Method Details

#destroyObject



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/json_api/controllers/relationships_controller.rb', line 47

def destroy
  authorize_resource_action!(@resource, action: :update, context: { relationship: @relationship_name })
  relationship_data = parse_relationship_data
  return head :no_content if relationship_data.nil?

  remove_relationship(relationship_data)
  finalize_relationship_removal(relationship_data)
rescue ArgumentError => e
  render_invalid_relationship_error(e)
rescue JSONAPI::Exceptions::ParameterNotAllowed => e
  render_parameter_not_allowed_error(e)
end

#showObject



31
32
33
34
# File 'lib/json_api/controllers/relationships_controller.rb', line 31

def show
  authorize_resource_action!(@resource, action: :show, context: { relationship: @relationship_name })
  render json: build_show_response, status: :ok
end

#updateObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/json_api/controllers/relationships_controller.rb', line 36

def update
  authorize_resource_action!(@resource, action: :update, context: { relationship: @relationship_name })
  relationship_data = parse_relationship_data
  update_relationship(relationship_data)
  save_and_render_relationship(relationship_data)
rescue ArgumentError => e
  render_invalid_relationship_error(e)
rescue JSONAPI::Exceptions::ParameterNotAllowed => e
  render_parameter_not_allowed_error(e)
end