Skip to content

Instantly share code, notes, and snippets.

@ismasan
Last active November 1, 2017 12:15
Show Gist options
  • Save ismasan/310d8846e4b9543f397abf1d4157d5fe to your computer and use it in GitHub Desktop.
Save ismasan/310d8846e4b9543f397abf1d4157d5fe to your computer and use it in GitHub Desktop.
Ejemplo resolviendo conflicto de nombres al crear producto en API Bootic
datos = shop.create_product(
title: ‘un nombre que ya existe’,
price: 1234,
_policies: {
ensure_unique: ‘title’
}
)
if datos.has?(:errors)
if datos.has?(:current_entity)
# hubo un conflicto con el título. datos.current_entity es el producto existente en Bootic
actualizar_bsale(datos.current_entity)
# current_entity es un producto completo, incluyendo el link #update_product()
# se puede usar para actualizar el producto existente en Bootic
datos = datos.current_entity.update_product(price: 1234)
else
# hubo algún otro tipo de error (validaciones, variantes, etc)
end
else
# todo bien aquí. El producto fue creado sin conflictos.
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment