In my controller, I have code like ...
...
if user.save
something = Something.where("thing = ?", thing)
if !(something.nil?)
render json: { something: something }
else
end
else
render json: { error: user.errors.full_messages }, status: :bad_request
end
I 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
instead of the ROLLBACK COMMENT area above, but this will not work. User user.save ends. He spits something on the "rails s", but he does not roll back the last transaction.
source
share