Replace javascript solution with ruby on rails solution