I have an api with the following POST route /carros
in the controller I have:
app/controllers/api/v1/cars_controller.rb
module API
module V1
class CarrosController < ApplicationController
skip_before_action :verify_authenticity_token
def create
@carro = Carro.new
@carro.marca = 'chevrolet'
@carro.modelo = 'impala'
@carro.color = 'azul'
@carro.save
end
end
end
end
In the view I have the following jbuilder:
app/views/api/v1/cars/create.json.jbuilder
json.ok true
json.carro do
json.marca @carro.marca
json.modelo @carro.modelo
json.color @carro.color
end
The cart is generated fine, with all its validations and the output jbuilder
also without problems, but a parameter may be missing in the header and result in a 406 Not Acceptable response , even with this response it still creates the cart, what I want is How do so that if there is a response 4xx 0 500 it does not create the cart?.