I’ve got a view that renders a menu. These menu items are dynamic, in that they only appear based on some conditions (authorization, for example).
I have two options:
- Hard code the menu in the view with all the necessary conditionals
- Structure and filter data outside of the view so the view is only responsible for displaying an array of actions.
Option 2 seems to be more elegant to me, but this seems to come at the cost of increasing the size of the controller and doesn’t feel like it should be the responsibility of the controller.
So, my questions are:
- Is structuring data for the view standard practice?
- Where should the structuring of this data live? I’ve considered using a helper method (imported from module), a service object, or just a private method within the controller, it’s just not clear to me which would be better.
Beyond just answering the above questions, I would appreciate any insights in how to approach these types of conceptual issues.
For what it’s worth, the MVC framework I’m using is rails.