If you’re just starting out, consider a controller a collection of
related actions. Often, you’ll find that a controller is tied to a
model, with actions for listing, reading, creating, deleting and editing
entries. A controller might also handle related models (ie. a
blog_controller might also handle comments, categories and tags in
addition to blog posts). Furthermore, a controller might not be related
to a specific model at all. For instance: you might have a controller
named Dashboard that provides an overview of the app.
Here’s a couple of things to have in mind:
- Don’t repeat yourself. Helpers and protected methods in a controller
are shared across all it’s actions and views.
- Think of the controller as a context for the action. Ie, you might
want to see a blog post in a different way in the Admin controller
compared to the Blog controller.