I’m new to Rails (and web development [but not new to Ruby]) and still getting my head around the conventions, let alone MVC.
I have a (simplified) set of models as follows, belongs_to associations excluded for clarity:
Contact (has_many :accounts)
Account (has_many :service_1s, has_many :service_2s)
Service1 (has_many :service_1_usage_records)
Service1UsageRecords (has_many :service_1_usage_records_historical)
Service1UsageRecordsHistorical ()
Service2 (has_many :service_2_usage_records)
Service2UsageRecords ()
I will need access to the REST actions for Contact, Account, Service1, and Service2 from the web interface. The other models are used in the back end.
Does this mean, in this situation, I would need four controllers, to account for the four sets of REST actions I require?
Think of controllers as controlling access to resources. You can make one controller that does everything, but it’s more maintainable to keep controllers to one per resource, which Rails urges you to do (routes, etc.)
From your description, it does sound like 4 controllers is what you’ll need. If you need to directly access any other resource through the web, you’ll probably want more controllers, but if not, the 4 you mentioned should be fine.