Coming back to Rails after being away from some time in Django land I discovered a huge difference in how Rails, Grails and Django treats your models. In Django and Grails you can look at a model class and see all the properties it has:
[python] class Organization(models.Model): name = models.CharField(max_length=255) url = models.URLField(verify_exists=False) orgtype = models.ForeignKey(OrgType) [/python]
The same model class in Rails typically looks like this:
[ruby] class Organization < ActiveRecord::Base belongs_to :OrgType end [/ruby]
…and in Grails it is more specific like Django:
[groovy] class Organization { String name String url static belongsTo = OrgType OrgType orgtype } [/groovy]
It took me a while to remember that in Rails, parts of the model design is actually stored in the database schema instead of in the Ruby code. Peculiar don’t you think, given that everything else in a Rails app is nicely declared in Ruby code? There are of course benefits to both approaches, but I have started adding comments in the Rails model classes to be able to remember what properties they have without peeking in the Db. Typically I have a number of half-baked projects on my laptop and from time to time I forget what they do and these comments help me remember.
Check out more examples here: