views:

27

answers:

1

I've currently got this in my view file:

<%= "<em>(#{package.to_company})</em>" unless package.to_company.blank? %>

Is my understanding correct that I should move that to a helper?

ie.

def package_company(package)
  "<em>(#{package.to_company})</em>" unless package.to_company.blank?
end

I ask because I've got a few dozen unless statements in this specific view based on if a user submits specific data or not. Seemed overkill to create a few dozen helper methods for just single unless statements.

+3  A: 

Create this helper if you'are going to re-use this exact chunk of code many times (and stay DRY)… if you're going to use it once, you don't need an helper…

Yannis