Functionally speaking, both seem like subroutines that generate HTML based on certain parameters.
Is the decision to use one or the other in a given circumstance purely aesthetic?
Helpers and partials are both intended to be used in your view layer. The difference is that helpers are primarily ruby code, intended to be used as a library of methods to call from your templates. Partials are .html.erb files containing partial templates that can be inserted into your main templates. So in short, logic should go into helpers and reusable html snippets (with minimal embedded logic) should be in partials. Hope this helps!
The decision is not purely aesthetic. You want to use helpers inside your views. For example, you would use a partial to generate the html for a product, but within that partial (or any other view), you could use a helper to generate part of the partial, that maybe needs some logic to determine exactly what to display.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With