asitmoharna
asitmoharna

Reputation: 1532

Ruby on Rails 3: In views when to use partial vs helper vs loop

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

Answers (1)

Michael Durrant
Michael Durrant

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

Related Questions