Ruby to Javascript conversion