rails-style-guide icon indicating copy to clipboard operation
rails-style-guide copied to clipboard

Suggestion: Avoid `render ... and return`

Open andyw8 opened this issue 2 years ago • 4 comments

Previously this pattern was used in the Rails docs examples but is now discouraged:

https://github.com/rails/rails/pull/45927/files

andyw8 avatar Sep 09 '22 14:09 andyw8

It's a controversial topic. https://github.com/rubocop/ruby-style-guide/pull/730 has been recently merged. Also related https://github.com/rubocop/ruby-style-guide/pull/785

pirj avatar Sep 09 '22 23:09 pirj

While .. and .. is now permitted by the default RuboCop settings, the main problem I see with the render ... and return pattern is that it incorrectly suggests we should not return if the render part somehow fails.

mvz avatar Dec 29 '23 12:12 mvz

Should we recommend return render …?

pirj avatar Dec 29 '23 13:12 pirj

I think it's better for the return to be a separate statement. Returning a value would suggest that it's used for something.

andyw8 avatar Dec 29 '23 14:12 andyw8