Structure conditionals properly, fast -> slow
Always put conditionals that don't trigger SQL queries first place in a conditional. Rather than:
if @post.author.posts.count > 1 && @post.published?
  ...
end
Put these quickest conditionals first, so if they return false, the other code won't be executed:
if @post.published? && @post.author.posts.count > 1
  ...
end
The same rule applies for slow methods. Put the quickest ones first, then the slower ones last. e.g.
if @post.published? && @post.calculate_rank > 5.0
  ...
endWritten by Kieran Pilkington
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
 #Ruby 
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#