Question

I have this code reek complains for DuplicateMethodCall (calls format.json twice)

if object_error.blank?
  format.json { render json: order }
else
  format.json { render json: object_error, status: :unprocessable_entity }
end

What is the best way to do it in rails? or is this false positive?

Was it helpful?

Solution

I think there is no need in refactoring in this particular case.

This, and other variations occurs errors too:

format.json { render(object_error.blank? ? (json: order) : (json: object_error, status: :unprocessable_entity) }

And it's less readable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top