- Never ever use tabs to indent, always 2 spaces
- Indent continued lines 2 spaces
- Indent private methods equal to public methods
- Avoid methods with more than 5 lines
- Avoid classes with more than 100 lines
- Avoid methods with more than 4 parameters
- Avoid explicit return statements
- Don't use
selfexplicitly anywhere except class methods (def self.method) and assignments (self.attribute =) - Prefer
detectoverfind - Prefer
injectoverreduce - Prefer
mapovercollect - Prefer
selectoverfind_all - Prefer single quotes for strings
- Use
_for unused block parameters - Use
%{}for single-line strings needing interpolation and double-quotes - Use
&&and||for Boolean expressions - Use
{...}for single-line blocks. Use do..end for multi-line blocks - Use
?suffix for predicate methods - Use
CamelCasefor classes and modules,snake_casefor variables and methods,SCREAMING_SNAKE_CASEfor constants - Use
def self.method, notdef Class.methodorclass << self - Use
defwith parentheses when there are arguments - Use
each, notfor, for iteration - Use heredocs for multi-line strings
- Avoid
memberandcollectionroutes - Avoid passing more than 1 object to the view in a controller action
- Don't use protected controller methods
- Name date columns with
_onsuffixes - Name datetime columns with
_atsuffixes - Name initializers for their gem name
- Order ActiveRecord associations alphabetically by attribute name
- Order ActiveRecord validations alphabetically by attribute name
- Order controller contents: filters, public methods, private methods
- Order model contents: constants, macros, public methods, private methods
- Put application-wide partials in the
app/views/applicationdirectory - Use
def self.method, not thescope :methodDSL - Use the default
render 'partial'syntax overrender partial: 'partial' - Avoid the
:exceptoption in routes - Order resourceful routes alphabetically by name
- Use the
:onlyoption to explicitly state exposed routes