2 thoughts on “When should I create more controllers/models?”

  1. I hear ya! I’m just learning too, but I’m thinking after they get so long, large, and hard to follow, go ahead and start a new one.

    Reply
  2. Data models can be hard and you shouldn’t feel bad about not feeling comfortable along the way. It’s easy to migrate from one data model to the other in Rails so don’t be afraid to expirement.

    A guideline: If you want to store metadata about an attribute, it’s time to take that attribute out of the current model and make a new associated model with the metadata as attributes. For example, you have a Car model with number_of_owners:integer attribute. If you want to know a lot of metadata (attributes) about the owners themselves, for example storing the age and gender of each owner, you can migrate towards Car has_many :owners, with an Owner model that has attributes gender:string and age:integer. You can now write a method in your Car model to replace the number_of_owners attribute like this:

    def number_of_owners; self.owners.count; end

    Reply

Leave a Comment