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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top