Давай вынесем в хелпер. Вот пример: 

https://github.com/Kavrus/icrm-manager/blob/develop/app/assets/javascripts/helpers/application_helpers.js.coffee
https://github.com/Kavrus/icrm-manager/blob/develop/app/assets/javascripts/views/visits/visit_view.js.coffee#L10