Created
April 28, 2009 20:23
-
-
Save jnstq/103378 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For some time here at EdgeCase we've had a bit of a standard for organization of model files in a Rails app. In the body of our model classes, we try to keep things in the following order: | |
1. Module includes | |
2. Class level constants | |
3. acts_as_whatever calls or similar extending method calls, for example attachment_fu's has_attachment | |
4. Associations, ex: has_many and belongs_to | |
5. Callbacks* | |
6. Validations | |
7. Named scopes | |
8. Class methods | |
9. Instance methods | |
10. Protected and private methods | |
I should also note that we are moving away from this style of class method definition: | |
class << self | |
def some_method | |
puts "banana" | |
end | |
end | |
In favor of: | |
def self.some_method | |
puts "banana" | |
end | |
We find that having a known file layout makes it easier for the other guys to find the line they are looking for when I break the build. | |
* All callbacks should go before validations. See this to find out why I say so. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment