I'd suggest pulling this into a helper.  ApplicationHelper would be fine.