Translations: English
Search on Docs:
ActionItem Search:

Coding conventions


The indentation is 2 spaces, for all the following languages.



Avoid using return in methods.

def method
instead of
def method
 return value

Access instance's methods using self.

The use self.method_name instead of just method_name make clear that an instance thing, not a variable, is being used.

Also, for setters, some times ommitting the self. will lead to a bug as it will create a variable instead of calling the instance method.

When a method has arguments, always use parenthesis in its declaration


  1. relationships (has_many, belongs_to, etc) and applied behaviour (acts_as_*)
  2. virtual attributes, if needed
  3. validations
  4. business logic in general

Thin controllers, fat models

  • every time you write a method with more than, say, 5 lines in a controller, consider if some of its logic shouldn't go inside a model class
  • NEVER reference anything but assigned @variables inside templates (.rhtml)


  • test every validation that you add to ActiveRecord models
  • add a test to your unit tests that passes all your fixtures through ActiveRecord validation, unless you are using an individual fixture as invalid data on purpose. Name your invalid data fixtures with "invalid_" as prefix.
  • every model must have unit tests
  • every controller must have functional tests. At least one test for each action.
  • every user story must have one or more corresponding integration tests.
  • Rcov reports must present 100% coverage of everything

Special Conventions



Add comment
You need to login to be able to comment.
Topic revision: r1 - 22 May 2015, UnknownUser

irc Talk with Devs Now!

Copyright © 2007-2019 by the Noosfero contributors
Colivre - Cooperativa de Tecnologias Livres