Refactored to use JS loop in template instead of ERB loop to generate multiple JS statements