Patterns of use for helpers and partials

Hello,

Are there any guidelines as to when helpers or partials are a better
option. If there is a lot of markup we are using partials, otherwise
it has been up to the developer.

Is there an established best practice?

Thanks,
Dan

Usually I favor helpers over partials when there’s more logic coding
than
markup and “display” coding involved. For example:

def display_date_range(start_date, end_date = false)
end_date = nil if end_date == start_date
[start_date, end_date].compact.each{|date| date = date.to_s(:view)
if
date.respond_to? :year}.join(’ - ')
end

That really feels more like it should be a helper than a partial. I
guess
that’s what matters - doing whatever feels right :slight_smile:

Daniel

+1

Helpers == logic
Partials are for rendering parts of views.

Leverage them both by making a helper call a partial :slight_smile: