In my controller I have some code like...
...
if user.save
something = Something.where("thing = ?", thing)
if !(something.nil?)
render json: { something: something }
else
#I WOULD LIKE TO ROLLBACK THE user.save HERE
end
else
render json: { error: user.errors.full_messages }, status: :bad_request
end
I have tried
raise ActiveRecord::Rollback, "Could not create new User, Something was not found."
render json: { error: "Could not create new User, Something was not found"}, status: :unprocessable_entity
in place of the ROLLBACK COMMENT area above, but this does not work. The user.save ends up going through. It spits something out to 'rails s', but it does not rollback the last transaction.