This seems extremely basic, but I've read a lot of related questions and haven't found a proper answer.
Using Ruby on Rails or other similar MVC framework, how am I supposed to load data that is displayed in sidebars on multiple pages?
Options I know of, with the problems I see:
- Load it in every controller method that needs it: causes duplication of code;
- Load it in a method on the ApplicationController, which is executed by all controllers: would cause data to be loaded even when not needed;
- Load it directly from the model in the view: not MVC?
I've asked this elsewhere and some people told me to "look into [insert another pattern here]" or "use Ajax calls to get the data". Although those might also work, I'm looking for an answer regarding MVC frameworks on the server.