Reputation: 1532
When to choose a partial or helper or a loop in view. Specifically, when we need a repeated structure only in a single page. I would like to know which one is a best practice from DRY point of view and Performance point of view.
Thanks.
Upvotes: 1
Views: 831
Reputation: 96484
If only in a single page, as described, I would consider using a loop or partial.
- If the output is one or two lines I might just use a loop.
- If more than that a partial
If used in multiple pages I would use a helper.
Overall I prefer helpers as they feel like a more object oriented, ruby approach and they are easy and great to have tests for!
Upvotes: 3