Should a view call a helper function?

Say I pass in data from the DB to the view. The data is a unix timestamp. Should I make a call in my view to convert it to a human readable TS or should I convert it in the controller before passing it in? OR should I make a method in the model that converts...

Looking for a "best practice" or "secure coding" concerned answer.

2 Answers 2


This seems like a fairly trivial calculation, indeed, you could implement it in a few lines of javascript. It is your view that is in charge of displaying data; let it do its work.

  • You are right... and I guess I couldn't come up with a better example. Maybe the question should be "When should you do each"?
    – Jeff
    Commented Jun 27, 2014 at 19:49
  • 1
    @Jeff: The view is responsible for massaging the data into the right form for display and that can include some calculations. Any calculations not related to displaying the data should go into the model. Commented Jun 28, 2014 at 6:24

Since human readability depends on the target output device (big screen TV, dashboard display, watch face, voice synthesis, Morse code tones/blinks, etc.), it might be best to customize this readability in the object most closely associated with the physical output device, likely the view object. The model objects can keep and pass on a binary encoded or computationally suitable form.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.