This is a really bad example. I am really against the short circuit and return method, because many people do not understand what this means, and in addition, this may be missed if you do not pay close attention.
A better approach is to describe where you have an explicit if that breaks out two possibilities. I would go further to collapse all of this into a single render call with an action argument defined ahead of time:
def show @book = Book.find(params[:id])
This example also lacked a trap for calling find , which could throw an exception if the record was not found. This is a common occurrence, and I'm sure most people completely forget about it. Remember that in a well-designed application, even when receiving bad requests, you should not display a โserver errorโ of 500.
The easiest way to avoid double rendering errors is to end up with only one render call.
source share